Problem with ASP.NET wizard hiding / removing steps

Discussion in 'ASP .Net Web Controls' started by tienleok@gmail.com, Jul 5, 2006.

  1. Guest

    Hi,

    When using the ASP.NET 2.0 Wizard control, I would like to hide Step 2 when the TextBox in Step 1 has a value of 1. The code below allows me to do that, but after removing Step 2, TextBox values in later steps no longer persist. (EnableViewState has no effect.)

    Can anyone enlighten me where my code is going wrong.

    Thanks in advance.

    Tien Leok


    I have the following code in my aspx page:

    <asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0" OnLoad="Wizard1_Load">
    <WizardSteps>
    <asp:WizardStep ID="WizardStep1" runat="server" Title="Step 1">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </asp:WizardStep>
    <asp:WizardStep ID="WizardStep2" runat="server" Title="Step 2">
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    </asp:WizardStep>
    <asp:WizardStep ID="WizardStep3" runat="server" Title="Step 3">
    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
    </asp:WizardStep>
    </WizardSteps>
    </asp:Wizard>

    and the following code in my aspx.cs:

    protected void Wizard1_Load(object sender, EventArgs e)
    {
    if (TextBox1.Text == "1")
    Wizard1.WizardSteps.Remove(WizardStep2);
    }
    , Jul 5, 2006
    #1
    1. Advertising

  2. ValliM Guest

    Hi Tien,

    The text value doesn't get retained as the page doesn't get posted back when
    you use previous button in Step3. To retain the text value of Step3 after
    traversing to other steps and returning to Step3, include the text value of
    TextBox3 in the ViewState.

    Coding:

    cs:
    private void Page_Load(object sender, System.EventArgs e)
    {

    if (ViewState["text3"] != null)

    {

    TextBox3.Text = ViewState["text3"].ToString();

    }



    }

    protected void Wizard1_Load(object sender, EventArgs e)

    {

    if (TextBox1.Text == "1")

    Wizard1.WizardSteps.Remove(WizardStep2);

    }

    protected void StoreValue(object sender, WizardNavigationEventArgs e)

    {

    if (TextBox3.Text != string.Empty)

    {

    ViewState["text3"] = TextBox3.Text;

    }


    }



    ASPX:

    <asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0"
    OnLoad="Wizard1_Load" OnPreviousButtonClick="StoreValue">

    <WizardSteps>

    <asp:WizardStep ID="WizardStep1" runat="server" Title="Step 1">

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

    </asp:WizardStep>

    <asp:WizardStep ID="WizardStep2" runat="server" Title="Step 2">

    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

    </asp:WizardStep>

    <asp:WizardStep ID="WizardStep3" runat="server" Title="Step 3">

    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>

    </asp:WizardStep>

    </WizardSteps>

    </asp:Wizard>



    Let me know if you have any doubts.



    Regards,

    Valli

    (www.syncfusion.com)

    ASP.Net FAQ:
    http://www.syncfusion.com/faq/aspnet/default.aspx

    Complete set of ASP.Net controls and components
    http://www.syncfusion.com/toolsweb



    <> wrote in message
    news:%...
    > Hi,
    >
    > When using the ASP.NET 2.0 Wizard control, I would like to hide Step 2
    > when the TextBox in Step 1 has a value of 1. The code below allows me to
    > do that, but after removing Step 2, TextBox values in later steps no
    > longer persist. (EnableViewState has no effect.)
    >
    > Can anyone enlighten me where my code is going wrong.
    >
    > Thanks in advance.
    >
    > Tien Leok
    >
    >
    > I have the following code in my aspx page:
    >
    > &lt;asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0"
    > OnLoad="Wizard1_Load"&gt;
    > &lt;WizardSteps&gt;
    > &lt;asp:WizardStep ID="WizardStep1" runat="server"
    > Title="Step 1"&gt;
    > &lt;asp:TextBox ID="TextBox1"
    > runat="server"&gt;&lt;/asp:TextBox&gt;
    > &lt;/asp:WizardStep&gt;
    > &lt;asp:WizardStep ID="WizardStep2" runat="server"
    > Title="Step 2"&gt;
    > &lt;asp:TextBox ID="TextBox2"
    > runat="server"&gt;&lt;/asp:TextBox&gt;
    > &lt;/asp:WizardStep&gt;
    > &lt;asp:WizardStep ID="WizardStep3" runat="server"
    > Title="Step 3"&gt;
    > &lt;asp:TextBox ID="TextBox3"
    > runat="server"&gt;&lt;/asp:TextBox&gt;
    > &lt;/asp:WizardStep&gt;
    > &lt;/WizardSteps&gt;
    > &lt;/asp:Wizard&gt;
    >
    > and the following code in my aspx.cs:
    >
    > protected void Wizard1_Load(object sender, EventArgs e)
    > {
    > if (TextBox1.Text == "1")
    > Wizard1.WizardSteps.Remove(WizardStep2);
    > }
    ValliM, Jul 5, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QmlsbCBHYXV2ZXk=?=

    ASP NET 2.0 Wizard Control - creating dynamic steps

    =?Utf-8?B?QmlsbCBHYXV2ZXk=?=, Oct 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,039
    =?Utf-8?B?QmlsbCBHYXV2ZXk=?=
    Oct 17, 2005
  2. Replies:
    0
    Views:
    596
  3. Nick Gilbert
    Replies:
    5
    Views:
    893
  4. Andy B
    Replies:
    0
    Views:
    434
    Andy B
    Apr 19, 2008
  5. Wizard Control and Removing Steps

    , Nov 29, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    259
Loading...

Share This Page