Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom RadioButtonList loses ViewState

Status
Not open for further replies.

rpeters74

Programmer
May 24, 2002
46
0
0
US
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
 
Tarnation! I was not Implementing INamingContainer on the RadioButtonList. Please ignore post.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top