Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7634911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:18:16+00:00 2026-05-31T07:18:16+00:00

I’m having some issues trying to keep the state of values in textbox controls

  • 0

I’m having some issues trying to keep the state of values in textbox controls between postbacks in a wizard that is part of a user-control (.ascx) file.

Some background

This is an order form for a product that can have different options (1 product can have many options), so the options are not generic.
A list of options (pulled from the database using SubSonic 2) is displayed to the user in the ‘start’ stage of the wizard for the selected product, using the syntax “OptionBox-4” (with the number on the end being the ID of the option in the database so i can go back later and grab the description.

The user can then enter different quantities in each of the options.

The problem

Once the user has entered the quantities in the boxes, and hit ‘next’ the Values are not being stored between postbacks, or the ID’s of the controls.

The code

<asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0"
    DisplaySideBar="False" onnextbuttonclick="Wizard1_NextButtonClick" 
    onpreviousbuttonclick="Wizard1_PreviousButtonClick" 
    FinishCompleteButtonText="Submit request"  
    onfinishbuttonclick="Wizard1_FinishButtonClick" 
    onactivestepchanged="Wizard1_ActiveStepChanged" 
    onprerender="Wizard1_PreRender" >
    <FinishPreviousButtonStyle CssClass="subbutton" />
    <FinishCompleteButtonStyle CssClass="subbutton" />
    <StartNextButtonStyle CssClass="subbutton" />
    <StepNextButtonStyle CssClass="subbutton" />
    <StepPreviousButtonStyle CssClass="subbutton" />
    <WizardSteps>
        <asp:WizardStep runat="server" StepType="Start" title="Description" ID="vgStep1">
            <fieldset class="emailform">
            <ul runat="server" id="optionList">
                <asp:PlaceHolder id="DynamicBoxes" runat="server" />
            </ul>
            </fieldset>
        </asp:WizardStep>
        <asp:WizardStep ID="WizardStep1" runat="server" Title="Your details" StepType="Finish">
            <h3>Order summary</h3>
            <asp:Literal ID="ltlSummary" runat="server"></asp:Literal>
        </asp:WizardStep>
        <asp:WizardStep ID="WizardStep2" runat="server" StepType="Complete" Title="Thank you">

        </asp:WizardStep>
    </WizardSteps>
</asp:Wizard>

the relevant codebehind

    class ResponseCollection : List<string> { }
private int? NrOfOptions
{
    get { return (int?)ViewState["NrOfOptions"]; }
    set { ViewState["NrOfOptions"] = value; }
}
public PartnerProductOrderableOptionCollection colOptions;
public PartnerProductOrderable prodOrderable;

protected void Page_Load(object sender, EventArgs e)
{
    LoadOrderWizard(Utility.GetPartnerProductId(Request.QueryString["ppid"]));
    CreateDynamicBoxes();
}

#region Ordering wizard
private void LoadOrderWizard(int p)
{

    partnerProduct = new PartnerProduct(p);

    prodOrderable = new PartnerProductOrderable("PartnerProductId", p);

    colOptions = new PartnerProductOrderableOptionCollection();
    colOptions.LoadAndCloseReader(PartnerProductOrderableOption.FetchByParameter("OrderableId", prodOrderable.OrderableId, OrderBy.Asc("ListOrder")));
    if (!IsPostBack)
    {
        this.NrOfOptions = colOptions.Count;
    }
}

protected void Wizard1_ActiveStepChanged(object sender, EventArgs e)
{
    if (Wizard1.ActiveStepIndex == 1)
    {
        ResponseCollection responses = CollectValuesFromDynamicBoxes();
        ltlSummary.Text += "Controls:";
        foreach (Control c in DynamicBoxes.Controls)
        {
            ltlSummary.Text += c.ID + ",";
            if (c is TextBox)
            {
                ltlSummary.Text += ((TextBox)c).ID + ",";
                if (!String.IsNullOrEmpty(((TextBox)c).Text))
                {
                    int optionid = int.Parse(c.ID.Split('-')[1]);
                    PartnerProductOrderableOption o = new PartnerProductOrderableOption(optionid);
                    ltlSummary.Text += "<strong>Quantity: </strong>" + ((TextBox)c).Text + "<br />";
                    ltlSummary.Text += "<strong>Description: </strong>" + o.Description + " - " + o.Price + "<hr />";

                }
            }
        }
    }
}

protected void Wizard1_PreviousButtonClick(object sender, WizardNavigationEventArgs e)
{
}

protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
    ResponseCollection responses = CollectValuesFromDynamicBoxes();
}
protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
{
    if (e.CurrentStepIndex == 0)
    {
        int newNumberOfOptions = colOptions.Count;
        int? oldNumberOfOptions = this.NrOfOptions;


        if (!oldNumberOfOptions.HasValue || newNumberOfOptions != oldNumberOfOptions.Value)
        {
            this.NrOfOptions = newNumberOfOptions;

            CreateDynamicBoxes();
        }
    }
}
private void CreateDynamicBoxes()
{
    if (!this.NrOfOptions.HasValue)
        return;

    DynamicBoxes.Controls.Clear();

    foreach (PartnerProductOrderableOption opt in colOptions)
    {
        HtmlGenericControl li = new HtmlGenericControl("li");
        DynamicBoxes.Controls.Add(li);

        TextBox box = new TextBox();
        box.ID = "OptionBox-" + opt.OptionId;
        box.Width = 40;
        box.MaxLength = 6;

        li.Controls.Add(box);

        Label lblOpt = new Label();
        lblOpt.ID = "lblOption-" + opt.OptionId;
        lblOpt.Text = opt.Description + " - " + opt.Price;
        li.Controls.Add(lblOpt);
    }
    this.NrOfOptions= colOptions.Count;
}

private ResponseCollection CollectValuesFromDynamicBoxes()
{
    ResponseCollection responses = new ResponseCollection();
    for (int i = 0; i < this.NrOfOptions.Value; i++)
    {
        TextBox box = (TextBox)DynamicBoxes.FindControl("OptionBox-" + i);
        string response = box.Text.Trim();

        if (response.Length > 0)
            responses.Add(response);
    }
    return responses;
}


protected void Wizard1_PreRender(object sender, EventArgs e)
{

}

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);

}

#endregion

The code is loosely based on http://aspnetresources.com/blog/dynamic_text_bBoxes_in_wizard_control which seems to do something very similar to what i need mine to do.

Another note

the LoadOrderWizard method has to be called in the Page_Load event. This is a stripped down code with only the code relevant to my issue shown. The control actually consists of a few different panels that display different information based on data passed to the control. therefore having initialisation code in the Page_Init event would fire un-necessarily.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:18:17+00:00Added an answer on May 31, 2026 at 7:18 am

    In the end, because i couldn’t find a workable solution to this, I have ended up using a session variable to store the id of the dynamic box and the value contained. I then on other pages check to see if the textbox id is contained within the session, and restore it’s value to the box.

    As only numbers get put in this box, this solution is a workaround for me. However it would still be nice to know if there is another solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm trying to create an if statement in PHP that prevents a single post
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.