[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

How To Get Access To Controls That You Add Programmatically on Postback

Asked by winterminute in Programming for ASP.NET

Tags: add, controls, postback

I have a web application in which I won't know the number of fields I need until runtime.  Say I'm reading a form structure from a database which will tell me all of the fields i need to generate. I then loop through that collection and add a label and a text box. It may be 3 or 30 controls I need to add. I'm looking the page you sent, but I'm not sure how it applies.

The controls are correctly generated for the user, but on post back they simply don't exist.  I tried looping through the controls in my panel, but it shows zero on postback. I tried looping through the entire page, but couldn't find any TextBox controls.

I read somewhere that seemed to imply that I need to recreate the controls on postback and ASP.NET would take care of settings values that the user entered.
I tried this, but the values don't get set.

If I run this code on postback, there are no Textbox on the page
private void LoopThroughControls(Control control)
{

foreach (Control frmCtrl in control.Controls)
{
  Response.Write(frmCtrl.GetType().ToString());
  Response.Write("<br />");

  if (frmCtrl.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
      RunTimeParams.Add(frmCtrl.ID, "Test");

  if (frmCtrl.HasControls() == true)
      LoopThroughControls(frmCtrl);
}

}


Here's the code I'm using to create the controls.

foreach(...)
{
Label FieldLabel = new Label();
FieldLabel.Text = FieldFromDB;

TextBox FieldTextBox = new TextBox();
RuntimeParamTextBox.ID = "DBField" + i;

TableRow InputTableRow = new TableRow();

TableCell InputTableCellLabel = new TableCell();
ParamInputTableCellLabel.Controls.Add(RuntimeParamLabel);

TableCell ParamInputTableCellText = new TableCell();
ParamInputTableCellText.Controls.Add(RuntimeParamTextBox);

ParamInputTableRow.Controls.Add(ParamInputTableCellLabel);
ParamInputTableRow.Controls.Add(ParamInputTableCellText);
ParamInputTable.Controls.Add(ParamInputTableRow);
}
RunTimeParamsPanel.Controls.Add(ParamInputTable);
[+][-]11/11/05 01:12 PM, ID: 15276946Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/11/05 03:27 PM, ID: 15277667Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/13/05 04:48 AM, ID: 15283117Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Programming for ASP.NET
Tags: add, controls, postback
Sign Up Now!
Solution Provided By: ihenry
Participating Experts: 3
Solution Grade: A
 
[+][-]02/21/06 07:30 PM, ID: 16015406Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]02/28/06 02:31 AM, ID: 16063548Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89