Hello everyone,
I need to use radio buttons in a datarepeater. The problem is that radio buttons do not get the same ID in repeaters, so cannot be mutually exclusive. One way I read about getting around this is to create my own radio button and just render it differently.
I am trying to create a server control that inherits from the radio button. It needs to support postback and async post backs and have event handlers. The code I have works fine, in the sense each radio button is mutually exclusive but events are not being fired. Can anyone tell me what I am missing? Here is what I have:
server control:
Code:
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> Public Class NewRadioButton
Inherits System.Web.UI.WebControls.WebControl
Implements System.Web.UI.IPostBackEventHandler
Public Event Click As EventHandler
' Invoke delegates registered with the Click event.
Protected Overridable Sub onClick(ByVal e As EventArgs)
RaiseEvent Click(Me, e)
End Sub
' Define the method of IPostBackEventHandler that raises change events.
Public Sub RaisePostBackEvent(ByVal eventArgument As String) _
Implements IPostBackEventHandler.RaisePostBackEvent
onClick(New EventArgs())
End Sub
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
Dim sb As New StringBuilder
sb.Append("<input id='" & Me.UniqueID & "' ")
sb.Append("type='radio' ")
sb.Append("name='" & Me.ID & "' ")
sb.Append("value='" & Me.ID & "' />")
Dim est As String = sb.ToString
writer.Write(sb.ToString)
End Sub
End Class
Here is how I implement the control:
Code:
<cd:NewRadioButton OnClick="setRBSelected" runat="server" ID="q1" />
and it's codebehind event handler:
Code:
Protected Sub setRBSelected(ByVal sender As Object, ByVal e As EventArgs)
' do something
end sub