I am trying to a very simple page using the Wizard Control but when the user inputs data into the auto generated textboxes, the data is not preserved on the final step.
I think is a matter of preserving the user state somehow. I come from ASP background but this ASP.NET on how the events and post backs is driving me crazy.
I already tried all the different events. How can I take values from a previous post back?
newProjectWizard.aspx
<%@ Page Language
="C#" AutoEventWireup="true" CodeFile="newProjectWizard.aspx.cs" Inherits="postbackTest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<
form id="form1" runat="server">
<div>
<asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0" >
<
WizardSteps>
<asp:WizardStep ID="WizardStep1" runat="server" Title="Enter number of inputs">
<asp:DropDownList ID
="ddlCategories" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem>1</
asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem Selected="True">3
</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5
</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7
</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9
</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
</asp:DropDownList>
</asp:WizardStep>
<asp:WizardStep ID="WizardStep2" runat="server" Title="Enter data to inputs" >
<asp
:PlaceHolder ID="PlaceHolder1" runat="server" OnLoad="generateTextboxes"></asp:PlaceHolder>
</asp:WizardStep>
<asp:WizardStep
ID="WizardStep3" runat="server" Title="Display user input" >
<asp:PlaceHolder ID="PlaceHolder2" runat="server" OnLoad="generateLabels"></asp:PlaceHolder>
</
asp:WizardStep>
</WizardSteps>
</asp:Wizard>
</div>
</form>
</body>
</html>
newProjectWizard.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class postbackTest : System.Web.UI.Page{
public void generateTextboxes(object sender, EventArgs e){
int numberOfTextboxesToBeCreated = Convert.ToInt16(ddlCategories.SelectedValue);
for (int i = 0; i < numberOfTextboxesToBeCreated; i++) {
TextBox tb =
new TextBox();
tb.Text = "change me " + i;
PlaceHolder1.Controls.Add(tb);
}
}
public void generateLabels(object sender, EventArgs e) {
int
numberOfTextboxesToBeCreated = Convert.ToInt16(ddlCategories.SelectedValue);
for (int i = 0; i < numberOfTextboxesToBeCreated; i++) {
Label l = new Label();
TextBox tb = (TextBox)PlaceHolder1.Controls[i];
l.Text = "[" + tb.Text + "]";
PlaceHolder2.Controls.Add(l);
}
}
}