Advertisement

05.14.2008 at 02:11PM PDT, ID: 23403184
[x]
Attachment Details

Persist state with dynamic controls

Asked by troycomp in .NET Framework 2.0, Programming for ASP.NET, WebApplications

Tags: microsoft, asp.net, 2.0

Dilemma. I have a page that will be populated with dynamically created controls when the user clicks the add button. They can click add as much as they want, but if the user refreshes the page, the page goes back to its original state with only the default control and all of the user inputs are lost. I need a way to keep track of the number of controls the user has added cause these controls have a lot of input and losing that will make anyone upset. Please dont say session variables, they are banned at my job. Viewstate wont work cause when a page is refreshed Viewstate is null again and isnt available until after the Init page lifecycle. Cant write to a file on the production web server, its prohibited. How can i keep track of the number of times the user clicked the add button without using the means already described?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
int myCount = 1; //initial # of controls displayed
    private TextBox[] dynamicTextBoxes; //self explanatory
 
//dynamic controls must be re created before the load event occurs
//otherwise values are lost
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        dynamicTextBoxes = new TextBox[myCount];
 
        for (int i = 0; i < myCount; i++)
        {
            TextBox textBox = new TextBox();
            textBox.ID = "myTextBox" + i.ToString();
            myPlaceHolder.Controls.Add(textBox);
            dynamicTextBoxes[i] = textBox;
            LiteralControl literalBreak = new LiteralControl("<br />");
            myPlaceHolder.Controls.Add(literalBreak);
        }
 
    }
[+][-]05.14.2008 at 02:28PM PDT, ID: 21568900

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.14.2008 at 02:32PM PDT, ID: 21568928

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

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

 
[+][-]05.14.2008 at 02:34PM PDT, ID: 21568949

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.14.2008 at 02:37PM PDT, ID: 21568969

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

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

 
[+][-]05.14.2008 at 02:46PM PDT, ID: 21569025

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.14.2008 at 02:52PM PDT, ID: 21569059

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

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

 
[+][-]05.14.2008 at 06:46PM PDT, ID: 21570078

View this solution now by starting your 7-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

Zones: .NET Framework 2.0, Programming for ASP.NET, WebApplications
Tags: microsoft, asp.net, 2.0
Sign Up Now!
Solution Provided By: raterus
Participating Experts: 2
Solution Grade: B
 
 
[+][-]05.15.2008 at 05:59AM PDT, ID: 21573033

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

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

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628