Reputation: 2489
I have a number of Input (textbox) controls that are created in the codebehind as part of a dynamic RadiobuttonList control (so that a textbox is next to a radiobutton):
RadioButtonList radioOption = new RadioButtonList();
radiobuttonlist.Items.Add(new ListItem(dt1.Rows[i][9].ToString() + " <input id=\"" + name + "\" runat=\"server\" type=\"text\" value=\"Enter text\" />")
My question is, how do I access the input text in order to set or get it's value?
There are in total around 10 different input controls created as part of a loop.
Any ideas would be greatly appreciated!!!!
Upvotes: 0
Views: 1640
Reputation: 330
What I would do is use the FindControl method. Based on what your id is, you can iterate through them and find the control - and then cast it to the particular control that it is.
TextBox textBox = (TextBox)Page.FindControl(id);
Then you can set and get on it:
textBox.text = "text";
string text = textBox.text;
EDIT: You may also need to add the runat="server" tag to the dynamically created text box in order to access it from the server side.
Upvotes: 1