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="cc" namespace="WroxControls" assembly="Webgridlib" %>
<%@ Register TagPrefix="uc" TagName="NameAddress" Src="NameAddress.ascx" %>
<%@ Register TagPrefix="uc" TagName="PolicyHeader" Src="PolicyHeader.ascx" %>
<%@ Register TagPrefix="uc" TagName="PolicyDates" Src="PolicyDates.ascx" %>
<%@ Page CodeBehind="PersonalDetails.aspx.vb" Language="vb" AutoEventWireup="false" Inherits="golf.PersonalDetails" %>
<HTML>
<body>
<form runat="server">
<P><asp:button id="Button1" runat="server" Text="Button"></asp:button><ASP:LABEL id="status" runat="server" EnableViewState="False"></ASP:LABEL></P>
<P> </P>
<P>
<cc:InsiteradiobuttonState autopostback="false" id="alliance" runat="server" datareference="alliance" enableviewstate="true"></cc:InsiteradiobuttonState></P>
</form>
<script runat="server" language="VB">
Private Sub OnNameChanged( sender As object, e As EventArgs )
status.text = "Value changed to " & 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("radiobuttonlist"
MyBase.New()
Context.Trace.Write("MyTextBox", "Created"
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("value" = 0 Then
' '_value = "notchanged"
' End If
' Return ViewState("value"
' End Get
' Set(ByVal value As Integer)
' ViewState("value" = value
' '_value = Me.Items(0).Selected
' If Me.Items(0).Selected = True Then
' '_value = "first"
' End If
' If Me.Items(1).Selected = True Then
' '_value = "second"
' End If
' If Me.Items(2).Selected = True Then
' '_value = "third"
' End If
' '_value = "7"
' 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, "radio"
Dim objDT As System.Data.DataTable = Page.Session("objFoxPro".gettable("policy"
'_value = objDT.Rows(0).Item(strDataReference)
'If Not (_value Is Nothing) Then
'writer.AddAttribute("checked", "on"
'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("MyTextBox", "Previous value:" & 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("objFoxPro".Replace("policy", strDataReference, 4)
Page.Session("objFoxPro".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("objFoxPro".GetTable("policy"
oRow = oTable.Rows(0)
'Text = oRow("paymeth", a)
_value = "POSTBACK!!"
Return re
End Function
Sub RaisePostDataChangedEvent()
'Implements IPostBackDataHandler.RaisePostDataChangedEvent
Dim eventhandler As EventHandler
eventhandler = CType(Events(_selectedindexChanged), EventHandler)
_value = "POSTBACK!!"
'RaiseEvent SelectedIndexChanged(Me, EventArgs.Empty)
End Sub
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
If (IsNothing(Page.Session("objFoxPro")) Then
Dim objFoxpro As DataManager.FoxPro = New DataManager.FoxPro()
Page.Session("objFoxPro" = objFoxpro
End If
Dim strStoredProcedureXMLFileName As String _
= "c:\inetpub\
Dim arrSPParams As New ArrayList()
arrSPParams.Add("MIS0000026A"
arrSPParams.Add(1999)
arrSPParams.Add("EGU19991"
Dim dtPolicy As System.Data.DataTable
dtPolicy = Page.Session("objFoxPro".ExecSPReturnDT("policy" _
, strStoredProcedureXMLFileName _
, arrSPParams)
Dim DataSource As ICollection
Dim arrItems As New ArrayList()
arrItems.Add("Standard"
arrItems.Add("Alliance & Leicester"
arrItems.Add("Barclays Unify"
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 + "<BR>"
'rad.GroupName = en.Current
'Controls.Add(rad)
End While
End Sub
End Class
Many thanks,
Glyn.
Here is the ASPX :-
<%@ Register TagPrefix="cc" namespace="WroxControls" assembly="Webgridlib" %>
<%@ Register TagPrefix="uc" TagName="NameAddress" Src="NameAddress.ascx" %>
<%@ Register TagPrefix="uc" TagName="PolicyHeader" Src="PolicyHeader.ascx" %>
<%@ Register TagPrefix="uc" TagName="PolicyDates" Src="PolicyDates.ascx" %>
<%@ Page CodeBehind="PersonalDetails.aspx.vb" Language="vb" AutoEventWireup="false" Inherits="golf.PersonalDetails" %>
<HTML>
<body>
<form runat="server">
<P><asp:button id="Button1" runat="server" Text="Button"></asp:button><ASP:LABEL id="status" runat="server" EnableViewState="False"></ASP:LABEL></P>
<P> </P>
<P>
<cc:InsiteradiobuttonState autopostback="false" id="alliance" runat="server" datareference="alliance" enableviewstate="true"></cc:InsiteradiobuttonState></P>
</form>
<script runat="server" language="VB">
Private Sub OnNameChanged( sender As object, e As EventArgs )
status.text = "Value changed to " & 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("radiobuttonlist"
MyBase.New()
Context.Trace.Write("MyTextBox", "Created"
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("value" = 0 Then
' '_value = "notchanged"
' End If
' Return ViewState("value"
' End Get
' Set(ByVal value As Integer)
' ViewState("value" = value
' '_value = Me.Items(0).Selected
' If Me.Items(0).Selected = True Then
' '_value = "first"
' End If
' If Me.Items(1).Selected = True Then
' '_value = "second"
' End If
' If Me.Items(2).Selected = True Then
' '_value = "third"
' End If
' '_value = "7"
' 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, "radio"
Dim objDT As System.Data.DataTable = Page.Session("objFoxPro".gettable("policy"
'_value = objDT.Rows(0).Item(strDataReference)
'If Not (_value Is Nothing) Then
'writer.AddAttribute("checked", "on"
'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("MyTextBox", "Previous value:" & 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("objFoxPro".Replace("policy", strDataReference, 4)
Page.Session("objFoxPro".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("objFoxPro".GetTable("policy"
oRow = oTable.Rows(0)
'Text = oRow("paymeth", a)
_value = "POSTBACK!!"
Return re
End Function
Sub RaisePostDataChangedEvent()
'Implements IPostBackDataHandler.RaisePostDataChangedEvent
Dim eventhandler As EventHandler
eventhandler = CType(Events(_selectedindexChanged), EventHandler)
_value = "POSTBACK!!"
'RaiseEvent SelectedIndexChanged(Me, EventArgs.Empty)
End Sub
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
If (IsNothing(Page.Session("objFoxPro")) Then
Dim objFoxpro As DataManager.FoxPro = New DataManager.FoxPro()
Page.Session("objFoxPro" = objFoxpro
End If
Dim strStoredProcedureXMLFileName As String _
= "c:\inetpub\
Dim arrSPParams As New ArrayList()
arrSPParams.Add("MIS0000026A"
arrSPParams.Add(1999)
arrSPParams.Add("EGU19991"
Dim dtPolicy As System.Data.DataTable
dtPolicy = Page.Session("objFoxPro".ExecSPReturnDT("policy" _
, strStoredProcedureXMLFileName _
, arrSPParams)
Dim DataSource As ICollection
Dim arrItems As New ArrayList()
arrItems.Add("Standard"
arrItems.Add("Alliance & Leicester"
arrItems.Add("Barclays Unify"
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 + "<BR>"
'rad.GroupName = en.Current
'Controls.Add(rad)
End While
End Sub
End Class
Many thanks,
Glyn.