Problem with ASP.NET wizard hiding / removing steps

T

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);
}
 
V

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top