The situation is as follows:
I'm trying to dynamically create RadButtons (type = option button) in an ASP:GridView. (maybe this should be in a RadGrid, but that's another conversation for another time)
What I did was dynamically add the RadButton on a button.click method as follows:
Dim dupOptionTop As RadButton = New RadButton()
dupOptionTop.GroupName = dgr.Cells(lnColumn).Text
dupOptionTop.ID = dupFile.FILEID
dupOptionTop.AutoPostBack = False
dupOptionTop.ButtonType = RadButtonType.ToggleButton
dupOptionTop.ToggleType = ButtonToggleType.Radio
dupOptionTop.ForeColor = Color.Brown
Dim dupOption As RadButtonToggleState = New RadButtonToggleState()
dupOptionTop.Text = dupFile.FILEID
dgr.Cells(lnMsgColumn + 1).Controls.Add(dupOptionTop)
I figure that the user could select from 2 or more choices, then iterate through the controls collection of a GridView cell to find which choice they selected and move on.
Unfortunately, while the new controls are on the users screen, they are unavailable for use in the code-behind. I'm now well aware that the code-behind can't see dynamically created controls unless they are set up in the Page_Init file. The problem is that it needs to have the data from the GridView loaded in order to create the controls, and that data won't load until AFTER the Page_Init event.
So I was thinking perhaps I can use the ViewState as follows in the Page_Load, and then use those to repopulate the GridView with the RadButtons:
Dim _options = New List(Of RadButton)
And then I run into this problem:
Type 'Telerik.Web.UI.RadButton' in Assembly 'Telerik.Web.UI, Version=2012.1.411.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4' is not marked as serializable.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.Serialization.SerializationException: Type 'Telerik.Web.UI.RadButton' in Assembly 'Telerik.Web.UI, Version=2012.1.411.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4' is not marked as serializable.
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Is there any way to get around this issue, or is there perhaps a much better way to accomplish this goal?
Thanks for any help you may have.