Forum Discussion
Using WebControlAdapter - CheckedChanged event not firing on RadioButton PostBack (WinForms)
[edit] I meant WebForms (in the title), not WinForms...
I am using a WebControlAdapter to render my radio buttons, but when I post (autoPostBack= True) my form back, the CheckedChange event is not firing (the PostBack is happening). This is my render code
Imports System.Web.UI.WebControls.Adapters
Public Class myRadio
Inherits WebControlAdapter
Protected Overrides Sub RenderBeginTag(ByVal writer As System.Web.UI.HtmlTextWriter)
' MyBase.RenderBeginTag(writer)
End Sub
Protected Overrides Sub RenderEndTag(ByVal writer As System.Web.UI.HtmlTextWriter)
' MyBase.RenderEndTag(writer)
End Sub
Protected Overrides Sub RenderContents(ByVal output As HtmlTextWriter)
Dim ctrl As RadioButton = CType(Me.Control, RadioButton)
Dim sb As New StringBuilder
Dim cntxt As HttpContext = HttpContext.Current
Try
If Page.IsPostBack Then
If cntxt.Request.Form.Count > 0 Then
Try
ctrl.Checked = CBool(cntxt.Request.Form(ctrl.GroupName) = ctrl.Text)
Catch ex As Exception
'
End Try
End If
End If
sb.Append("<label><input class=""")
sb.Append(ctrl.CssClass)
sb.Append(""" type=""radio""")
sb.Append(" name=""")
sb.Append(ctrl.GroupName)
sb.Append("""")
sb.Append(" value=""")
sb.Append(ctrl.Text)
sb.Append("""")
sb.Append(" id=""")
sb.Append(ctrl.ID)
sb.Append("""")
If ctrl.Checked Then sb.Append(" checked=""checked"" ")
If ctrl.AutoPostBack Then
sb.Append(" onclick=""javascript:setTimeout('__doPostBack(\'" & ctrl.ID & "\',\'\')', 0)"" ")
End If
sb.Append("> ")
sb.Append(ctrl.Text)
sb.Append("</label>")
Catch ex As Exception
sb = New StringBuilder
sb.Append("Error building Control:<br />")
sb.Append(ex.Message)
End Try
output.Write(sb.ToString)
End Sub
End Class
I have my MyAdapters.browser file set up, and the radio button is rendering as I want, and on (auto)postback it shows the correct checked state, but the CheckedChanged event won't fire. What am I not doing right?
3 Replies
- LanHuangFormer Employee
Hi PhilU115,
Thanks for posting your issue here.
However this platform is used for how-to discussions and sharing best practices for building any app with .NET.Since your issue is a technical question, welcome to post it in Microsoft Q&A forum, the support team and communities on Microsoft Q&A will help you for any technical questions.
Besides, it will be appreciated if you can share it here once you post this technical question Microsoft Q&A.
Best Regards,
Lan Huang- PhilU115Copper Contributortbh, I am really quite annoyed at your reply. I think you should delete it.