I have some dynamic controls in ASP.NET. I need to retrieve a value on postback from a control that no longer exists.
The following code works perfectly:
value = Request.Form["ctl00$ContentPlaceHolder1$text_name"];
However, I'm wondering if there's an elegant way to dynamically generate the "ctl00$ContentPlaceHolder$"
part or to get the value of textbox_value.UniqueID
when the control no longer exists.
Apologies if this question's come up a million times before - just looking for a more elegant solution that doesn't involve changing any settings on the server.
Edit:
As requested, the code for adding controls is like this:
foreach (NameValuePair entry in database_table){
Label label = new Label();
label.ID = "label_" + entry.Name;
label.Value = entry.Name;
label.Attributes.Add("runat", "server");
TextBox textBox = new TextBox();
textBox.ID = "text_" + entry.Name;
textBox.Text = entry.Value;
textBox.Attributes.Add("runat", "server");
}
On a button click, it reads name-value pairs from a database table (the number of entries is not static), allows them to be modified and saves them when a "save" button is pressed. It functions like a pop-up, so the fields are gone on postback. (I would prefer not to change this part of the code)
Thanks~