Hi.
I created a Custom DropDownList that inherits from WebControl. The Custom DropDownList creates a DropDownList and a RequiredFeidlValidator in the CreateChildControls() event. This control works 100%.
I created a custom RadioButtonList in the exact same manner as I described above. Problem is that the SelectedItem is lost on postbacks. I can not seem to understand this behavior as both controls contain the same Item type (the ListItem).
The code is below. If you replace RadioButtonList w/ DropDownList the control works. If does not as it is posted.
Any insight would be much appreciated.
=============================
Public Class RequiredRadioButtonList
Inherits WebControl
Private c_reqValRequired As RequiredFieldValidator
Private c_radRadioButtonList As RadioButtonList
Protected Overrides Sub CreateChildControls()
Me.c_radRadioButtonList = New RadioButtonList
Me.c_radRadioButtonList.ID = "radRadioButtonList"
Me.c_reqValRequired = New RequiredFieldValidator
Me.c_reqValRequired.ControlToValidate =
Me.c_radRadioButtonList.ID
Me.c_reqValRequired.ErrorMessage = "Data is Required"
Me.Controls.Add(Me.c_radRadioButtonList)
Me.Controls.Add(Me.c_reqValRequired)
End Sub
End Class
I created a Custom DropDownList that inherits from WebControl. The Custom DropDownList creates a DropDownList and a RequiredFeidlValidator in the CreateChildControls() event. This control works 100%.
I created a custom RadioButtonList in the exact same manner as I described above. Problem is that the SelectedItem is lost on postbacks. I can not seem to understand this behavior as both controls contain the same Item type (the ListItem).
The code is below. If you replace RadioButtonList w/ DropDownList the control works. If does not as it is posted.
Any insight would be much appreciated.
=============================
Public Class RequiredRadioButtonList
Inherits WebControl
Private c_reqValRequired As RequiredFieldValidator
Private c_radRadioButtonList As RadioButtonList
Protected Overrides Sub CreateChildControls()
Me.c_radRadioButtonList = New RadioButtonList
Me.c_radRadioButtonList.ID = "radRadioButtonList"
Me.c_reqValRequired = New RequiredFieldValidator
Me.c_reqValRequired.ControlToValidate =
Me.c_radRadioButtonList.ID
Me.c_reqValRequired.ErrorMessage = "Data is Required"
Me.Controls.Add(Me.c_radRadioButtonList)
Me.Controls.Add(Me.c_reqValRequired)
End Sub
End Class