Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > cannot get value of dropdownlist from postback

Reply
Thread Tools

cannot get value of dropdownlist from postback

 
 
Kevin Blount
Guest
Posts: n/a
 
      09-06-2006
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">
<aspanel 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 >" />
</aspanel>


<aspanel 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 >" />
</aspanel>

<aspanel ID="panel3" runat="server" Wrap="true">
<h2>Panel 3</h2>
<%
ListItem languageSelectItem = new ListItem("TextToAppear","ValueToUse");
textList.Items.Add(languageSelectItem);
%>
<aspropDownList ID="textList" runat="server"
EnableViewState="false"></aspropDownList>
<asp:Button ID="show_panel4" CommandName="show_panel4"
OnCommand="button_click" runat="server" Text="Finish" />
</aspanel>

<aspanel ID="panel4" runat="server" Wrap="true">
<%
Response.Write(username.Text + " - " + textCheckBox.Text + " - " +
textList.Text);
%>
</aspanel>
</form>

</body>
 
Reply With Quote
 
 
 
 
Jon Paal
Guest
Posts: n/a
 
      09-07-2006
perhaps you could use an event handler to pick up the droplist value selected and assign it to a page level variable then you could
reference that variable instead of the droplist for later usage.


"Kevin Blount" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>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">
> <aspanel 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 >" />
> </aspanel>
>
>
> <aspanel 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 >" />
> </aspanel>
>
> <aspanel ID="panel3" runat="server" Wrap="true">
> <h2>Panel 3</h2>
> <%
> ListItem languageSelectItem = new ListItem("TextToAppear","ValueToUse");
> textList.Items.Add(languageSelectItem);
> %>
> <aspropDownList ID="textList" runat="server" EnableViewState="false"></aspropDownList>
> <asp:Button ID="show_panel4" CommandName="show_panel4" OnCommand="button_click" runat="server" Text="Finish" />
> </aspanel>
>
> <aspanel ID="panel4" runat="server" Wrap="true">
> <%
> Response.Write(username.Text + " - " + textCheckBox.Text + " - " + textList.Text);
> %>
> </aspanel>
> </form>
>
> </body>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to force a postback on a value change of a dropDownList gili.benshimon@gmail.com Java 0 02-27-2007 10:54 PM
Dropdownlist value is same as text after postback and in HTML (2.0 =?Utf-8?B?R2VvZmZyZXkgdmFuIGRlbiBPdWRlbg==?= ASP .Net 1 03-13-2006 01:27 AM
dropdownlist does not retain its selectedindex value on postback. John Blair ASP .Net 2 08-02-2005 10:03 PM
Dropdownlist selected value lost after postback Celine ASP .Net 3 09-03-2004 10:57 PM
ListBox inside a WebControl cannot get postback value. Felix Chan ASP .Net Web Controls 2 10-01-2003 10:29 PM



Advertisments