Further to my earleir question about custom rendering of web controls here: SImple ASP.NET web usercontrol to overwrite default rendered HTML I have tried to achieve the same thing using Control Adapters (linked to Radio buttons in the MyAdapter.Browser file)
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 Render(ByVal output As HtmlTextWriter)
Dim ctrl As RadioButton = CType(Me.Control, RadioButton)
Dim sb As New StringBuilder
Try
sb.Append("<label><input class=""")
sb.Append(ctrl.CssClass)
sb.Append(""" type=""radio""")
sb.Append(" name=""")
sb.Append(ctrl.GroupName)
sb.Append("""")
sb.Append(" id=""")
sb.Append(ctrl.ID)
sb.Append("""")
If ctrl.Checked Then sb.Append(" checked")
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
This renders the controls just as I want - but again, state is not preserved on PostBack (specifically, teh "checked" state). As this is linked to RadioButtons and is supposed to just change how the HTML is rendered, I don't understand why. But whyever, how can I get the checked state of it on PostBack?