K
Kevin Blount
I have a test script right now that I'm fighting with. The idea is to
"simply" have an aspx page with 3 panels, to show 3 "different" forms
and then a 4th panel to show the results of processing these forms.
One of the panels will contain DropDownLists, who's items are
dynamically added in terms of text and values. For example, one of these
lists will be languages. I want to list presented in the language of the
person viewing it, i.e. if they are visiting out French website, they
see "Français", but if they are on our UK website they see "French". The
value will always be "French".
The problem I'm find is that when the panel with the DropDownList is not
visible, then I cannot access the .Text property of the list. In the
code below, I have a DropDownList called "testList", and right at the
end of the code I do a Response.Write to show testList.Text; but this
will only work when panel3.Visible = true.
Naturally this isn't going to work, as if my 3 forms (in panels 1, 2 &
3) are going to work properly, they must be hidden until required, and
once the form fields on panel3 are completed, they should all be hidden.
Is there any way to change the code below to make this work even if the
panel holding the DropDownList is hidden?
Many thanks
Here's the code:
<body>
<script runat="server">
public string usernameString = string.Empty;
private void Page_Load(object sender, EventArgs e)
{
usernameString = Request["username"];
hideAllPanels();
if (!IsPostBack)
{
panel1.Visible = true;
}
}
private void button_click(object sender,
System.Web.UI.WebControls.CommandEventArgs e)
{
if (e.CommandName == "show_panel2")
{
panel2.Visible = true;
}
else if(e.CommandName == "show_panel3")
{
panel3.Visible = true;
}
else if(e.CommandName == "show_panel4")
{
panel3.Visible = false;
panel4.Visible = true;
}
}
private void hideAllPanels() {
panel1.Visible = false;
panel2.Visible = false;
panel3.Visible = false;
panel4.Visible = false;
}
</script>
<%
%>
<form action="" method="post" name="pageform" id="pageform" runat="server">
<asp
anel ID="panel1" runat="server" Wrap="true">
<h2>Panel 1</h2>
<asp:TextBox ID="username" runat="server" />
<asp:RequiredFieldValidator id="RequiredFieldValidator1"
CssClass="smallFontRed" runat="server" Height="8px" ErrorMessage="This
field is required"
ControlToValidate="username"></asp:RequiredFieldValidator>
<asp:Button ID="show_panel2" CommandName="show_panel2"
OnCommand="button_click" runat="server" Text="Next >" />
</asp
anel>
<asp
anel ID="panel2" runat="server" Wrap="true">
<h2>Panel 2</h2>
<asp:CheckBox ID="textCheckBox" runat="server" Value="as test"
Text="booyah" />
<asp:Button ID="show_panel3" CommandName="show_panel3"
OnCommand="button_click" runat="server" Text="Next >" />
</asp
anel>
<asp
anel ID="panel3" runat="server" Wrap="true">
<h2>Panel 3</h2>
<%
ListItem languageSelectItem = new ListItem("TextToAppear","ValueToUse");
textList.Items.Add(languageSelectItem);
%>
<asp
ropDownList ID="textList" runat="server"
EnableViewState="false"></asp
ropDownList>
<asp:Button ID="show_panel4" CommandName="show_panel4"
OnCommand="button_click" runat="server" Text="Finish" />
</asp
anel>
<asp
anel ID="panel4" runat="server" Wrap="true">
<%
Response.Write(username.Text + " - " + textCheckBox.Text + " - " +
textList.Text);
%>
</asp
anel>
</form>
</body>
"simply" have an aspx page with 3 panels, to show 3 "different" forms
and then a 4th panel to show the results of processing these forms.
One of the panels will contain DropDownLists, who's items are
dynamically added in terms of text and values. For example, one of these
lists will be languages. I want to list presented in the language of the
person viewing it, i.e. if they are visiting out French website, they
see "Français", but if they are on our UK website they see "French". The
value will always be "French".
The problem I'm find is that when the panel with the DropDownList is not
visible, then I cannot access the .Text property of the list. In the
code below, I have a DropDownList called "testList", and right at the
end of the code I do a Response.Write to show testList.Text; but this
will only work when panel3.Visible = true.
Naturally this isn't going to work, as if my 3 forms (in panels 1, 2 &
3) are going to work properly, they must be hidden until required, and
once the form fields on panel3 are completed, they should all be hidden.
Is there any way to change the code below to make this work even if the
panel holding the DropDownList is hidden?
Many thanks
Here's the code:
<body>
<script runat="server">
public string usernameString = string.Empty;
private void Page_Load(object sender, EventArgs e)
{
usernameString = Request["username"];
hideAllPanels();
if (!IsPostBack)
{
panel1.Visible = true;
}
}
private void button_click(object sender,
System.Web.UI.WebControls.CommandEventArgs e)
{
if (e.CommandName == "show_panel2")
{
panel2.Visible = true;
}
else if(e.CommandName == "show_panel3")
{
panel3.Visible = true;
}
else if(e.CommandName == "show_panel4")
{
panel3.Visible = false;
panel4.Visible = true;
}
}
private void hideAllPanels() {
panel1.Visible = false;
panel2.Visible = false;
panel3.Visible = false;
panel4.Visible = false;
}
</script>
<%
%>
<form action="" method="post" name="pageform" id="pageform" runat="server">
<asp

<h2>Panel 1</h2>
<asp:TextBox ID="username" runat="server" />
<asp:RequiredFieldValidator id="RequiredFieldValidator1"
CssClass="smallFontRed" runat="server" Height="8px" ErrorMessage="This
field is required"
ControlToValidate="username"></asp:RequiredFieldValidator>
<asp:Button ID="show_panel2" CommandName="show_panel2"
OnCommand="button_click" runat="server" Text="Next >" />
</asp

<asp

<h2>Panel 2</h2>
<asp:CheckBox ID="textCheckBox" runat="server" Value="as test"
Text="booyah" />
<asp:Button ID="show_panel3" CommandName="show_panel3"
OnCommand="button_click" runat="server" Text="Next >" />
</asp

<asp

<h2>Panel 3</h2>
<%
ListItem languageSelectItem = new ListItem("TextToAppear","ValueToUse");
textList.Items.Add(languageSelectItem);
%>
<asp

EnableViewState="false"></asp

<asp:Button ID="show_panel4" CommandName="show_panel4"
OnCommand="button_click" runat="server" Text="Finish" />
</asp

<asp

<%
Response.Write(username.Text + " - " + textCheckBox.Text + " - " +
textList.Text);
%>
</asp

</form>
</body>