Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am trying to create a custom radi

Status
Not open for further replies.

protechdm

Programmer
Dec 30, 2001
36
GB
I am trying to create a custom radiobuttonlist. The problem is that I cannot seem to fire the "LoadPostData" method which needs to update the datatable with the selectedindex value. It works fine when a class is defined as a WebControl, the textbox class I have written calls postback perfectly. The code is heavily commented out as I have been trying loads of different routes to overcome it but you should get the picture.

Here is the ASPX :-

<%@ Register TagPrefix=&quot;cc&quot; namespace=&quot;WroxControls&quot; assembly=&quot;Webgridlib&quot; %>
<%@ Register TagPrefix=&quot;uc&quot; TagName=&quot;NameAddress&quot; Src=&quot;NameAddress.ascx&quot; %>
<%@ Register TagPrefix=&quot;uc&quot; TagName=&quot;PolicyHeader&quot; Src=&quot;PolicyHeader.ascx&quot; %>
<%@ Register TagPrefix=&quot;uc&quot; TagName=&quot;PolicyDates&quot; Src=&quot;PolicyDates.ascx&quot; %>
<%@ Page CodeBehind=&quot;PersonalDetails.aspx.vb&quot; Language=&quot;vb&quot; AutoEventWireup=&quot;false&quot; Inherits=&quot;golf.PersonalDetails&quot; %>
<HTML>
<body>
<form runat=&quot;server&quot;>
<P><asp:button id=&quot;Button1&quot; runat=&quot;server&quot; Text=&quot;Button&quot;></asp:button><ASP:LABEL id=&quot;status&quot; runat=&quot;server&quot; EnableViewState=&quot;False&quot;></ASP:LABEL></P>
<P>&nbsp;</P>
<P>
<cc:InsiteradiobuttonState autopostback=&quot;false&quot; id=&quot;alliance&quot; runat=&quot;server&quot; datareference=&quot;alliance&quot; enableviewstate=&quot;true&quot;></cc:InsiteradiobuttonState></P>
</form>
<script runat=&quot;server&quot; language=&quot;VB&quot;>

Private Sub OnNameChanged( sender As object, e As EventArgs )

status.text = &quot;Value changed to &quot; & alliance.peek

End Sub


</script>
</body>
</HTML>






Here is the class :-

Public Class InsiteRadioButtonState
Inherits WebControls.RadioButtonList
'Implements IPostBackDataHandler, INamingContainer

Public Sub New()
'MyBase.New(&quot;radiobuttonlist&quot;)
MyBase.New()
Context.Trace.Write(&quot;MyTextBox&quot;, &quot;Created&quot;)

End Sub 'New

Private Shared _textChanged As New Object()
Private Shared _selectedindexChanged As New Object()

Public Event TextChanged As EventHandler
'Public Event selectedindexchanged As EventHandler

Private _value As String
Public ReadOnly Property peek() As String
Get
Return _value
End Get
End Property

'Public Property SelectedIndex() As Integer
' Get
' If ViewState(&quot;value&quot;) = 0 Then
' '_value = &quot;notchanged&quot;
' End If

' Return ViewState(&quot;value&quot;)
' End Get
' Set(ByVal value As Integer)
' ViewState(&quot;value&quot;) = value
' '_value = Me.Items(0).Selected
' If Me.Items(0).Selected = True Then
' '_value = &quot;first&quot;
' End If
' If Me.Items(1).Selected = True Then
' '_value = &quot;second&quot;
' End If
' If Me.Items(2).Selected = True Then
' '_value = &quot;third&quot;
' End If
' '_value = &quot;7&quot;
' End Set
'End Property

Private strDataReference As String
Public Property DataReference() As String
Get
Return strDataReference
End Get
Set(ByVal Value As String)
strDataReference = Value
End Set
End Property

Protected Overrides Sub AddAttributesToRender(ByVal writer As HtmlTextWriter)

MyBase.AddAttributesToRender(writer)
writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID)

writer.AddAttribute(HtmlTextWriterAttribute.Type, &quot;radio&quot;)
Dim objDT As System.Data.DataTable = Page.Session(&quot;objFoxPro&quot;).gettable(&quot;policy&quot;)

'_value = objDT.Rows(0).Item(strDataReference)

'If Not (_value Is Nothing) Then
'writer.AddAttribute(&quot;checked&quot;, &quot;on&quot;)
'End If

End Sub

Function LoadPostData(ByVal postDataKey As String, ByVal postCollection As NameValueCollection) As Boolean
'Implements IPostBackDataHandler.LoadPostData

Dim re As Boolean = False

'Context.Trace.Write(&quot;MyTextBox&quot;, &quot;Previous value:&quot; & SelectedIndex)

'If postCollection(postDataKey) = True Then
'Checked = True
'Else
'Checked = 8
'End If

'If Checked <> postCollection(postDataKey) Then
re = True
'End If

'Checked = postCollection(postDataKey)

Page.Session(&quot;objFoxPro&quot;).Replace(&quot;policy&quot;, strDataReference, 4)
Page.Session(&quot;objFoxPro&quot;).savechanges()
Dim a As System.Data.DataRowVersion
a = System.Data.DataRowVersion.Original
Dim oRow As System.Data.DataRow
Dim oTable As System.Data.DataTable
oTable = Page.Session(&quot;objFoxPro&quot;).GetTable(&quot;policy&quot;)
oRow = oTable.Rows(0)
'Text = oRow(&quot;paymeth&quot;, a)
_value = &quot;POSTBACK!!&quot;
Return re
End Function


Sub RaisePostDataChangedEvent()
'Implements IPostBackDataHandler.RaisePostDataChangedEvent

Dim eventhandler As EventHandler

eventhandler = CType(Events(_selectedindexChanged), EventHandler)
_value = &quot;POSTBACK!!&quot;

'RaiseEvent SelectedIndexChanged(Me, EventArgs.Empty)
End Sub

Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
If (IsNothing(Page.Session(&quot;objFoxPro&quot;))) Then
Dim objFoxpro As DataManager.FoxPro = New DataManager.FoxPro()
Page.Session(&quot;objFoxPro&quot;) = objFoxpro

End If

Dim strStoredProcedureXMLFileName As String _
= &quot;c:\inetpub\
Dim arrSPParams As New ArrayList()
arrSPParams.Add(&quot;MIS0000026A&quot;)
arrSPParams.Add(1999)
arrSPParams.Add(&quot;EGU19991&quot;)

Dim dtPolicy As System.Data.DataTable
dtPolicy = Page.Session(&quot;objFoxPro&quot;).ExecSPReturnDT(&quot;policy&quot; _
, strStoredProcedureXMLFileName _
, arrSPParams)

Dim DataSource As ICollection
Dim arrItems As New ArrayList()
arrItems.Add(&quot;Standard&quot;)
arrItems.Add(&quot;Alliance & Leicester&quot;)
arrItems.Add(&quot;Barclays Unify&quot;)
DataSource = arrItems
'Me.DataSource = DataSource
Me.DataBind()
'Me.DataTextField = arrItems(0)
Dim rad As RadioButton
'Dim rad As TextBox

Dim en As IEnumerator = DataSource.GetEnumerator
While en.MoveNext
rad = New RadioButton()
'rad = New TextBox()
rad.ID = en.Current
rad.Text = en.Current.ToString + &quot;<BR>&quot;
'rad.GroupName = en.Current
'Controls.Add(rad)
End While
End Sub

End Class



Many thanks,

Glyn.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top