Home All Groups Group Topic Archive Search About

Problem with ASP.NET wizard hiding / removing steps

Author
5 Jul 2006 2:59 AM
tienleok
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);
    }

Author
5 Jul 2006 6:31 AM
ValliM
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



<tienl***@gmail.com> wrote in message
Show quoteHide quote
news:%23gMsZ89nGHA.4124@TK2MSFTNGP03.phx.gbl...
> 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);
>    }