Results 1 to 2 of 2

Thread: Problem creating server control

  1. #1

    Thread Starter
    Hyperactive Member jasonwucinski's Avatar
    Join Date
    Mar 2010
    Location
    Pittsburgh
    Posts
    452

    Problem creating server control

    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
    if i was able to help, rate my post!

  2. #2
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Problem creating server control

    Hello,

    Have you set breakpoints in your code?

    Are any of them getting hit?

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width