J
JP
I created a page that has dynamically created TextBox or DropDownList controls.
However once the text box is filled in and I submit the page, I cannot find
the dynamic control. I have been all over the net looking for an answer. I
read the article from 4GuysFromRolla but it still does not answer my question.
How to I retrieve the values from a dynamically created control on postback?
This was the name of the control I added to a GridView (AJAX call)
TextBox controlTextBox = new TextBox();
controlTextBox.EnableViewState = true;
controlTextBox.ID = "txt" + drControls["controlName"].ToString();
controlTextBox.MaxLength = 6;
controlTextBox.Width = 150;
controlTextBox.Enabled = true;
controlTextBox.Visible = true;
controlTextBox.Attributes.Add("runat", "server"); //just for the heck of it
e.Row.Cells[2].Controls.Add(controlTextBox);
(All is well at this point and the control is visible on the page)
if(IsPostBack)
{
//Control never found
string Answer= ((TextBox)GridView.FindControl("txtTransID")).Text;
}
I understand that the control itself (GUI representation) needs to be
recreated, but should not the control properties be in the viewstate to
access them?
PLEASE HELP! Does anyone have a working example? I could care less that the
controls get re-rendered on the postback as they get redirected to a
different screen after the data saves, but I really need to just access the
value
However once the text box is filled in and I submit the page, I cannot find
the dynamic control. I have been all over the net looking for an answer. I
read the article from 4GuysFromRolla but it still does not answer my question.
How to I retrieve the values from a dynamically created control on postback?
This was the name of the control I added to a GridView (AJAX call)
TextBox controlTextBox = new TextBox();
controlTextBox.EnableViewState = true;
controlTextBox.ID = "txt" + drControls["controlName"].ToString();
controlTextBox.MaxLength = 6;
controlTextBox.Width = 150;
controlTextBox.Enabled = true;
controlTextBox.Visible = true;
controlTextBox.Attributes.Add("runat", "server"); //just for the heck of it
e.Row.Cells[2].Controls.Add(controlTextBox);
(All is well at this point and the control is visible on the page)
if(IsPostBack)
{
//Control never found
string Answer= ((TextBox)GridView.FindControl("txtTransID")).Text;
}
I understand that the control itself (GUI representation) needs to be
recreated, but should not the control properties be in the viewstate to
access them?
PLEASE HELP! Does anyone have a working example? I could care less that the
controls get re-rendered on the postback as they get redirected to a
different screen after the data saves, but I really need to just access the
value