473,491 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

cannot get value of dropdownlist from postback

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:Panel 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:Panel>
<asp:Panel 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:Panel>

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

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

</body>
Sep 6 '06 #1
1 4106
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" <ke**********@LOLgmail.comwrote in message news:uC**************@TK2MSFTNGP06.phx.gbl...
>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:Panel 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:Panel>
<asp:Panel 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:Panel>

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

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

</body>

Sep 7 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1745
by: John Smith | last post by:
I have a Repeater that is paginated, and I would like the user to navigate to each page via a DropDownList. I have set the AutPostBack attribute to true and written code that fires on the...
1
5611
by: Mike | last post by:
I create a dynamic control and added it to a panel. I get the selected value of the control via a btn_click() but my problem is everytime the page is postback the selected values go back to the...
1
2459
by: Harry | last post by:
Hi, Just seeing if anyone can help me with a problem I am having with drop down lists. - I have a asp:dropdownlist that gets its values from a database. - The user then selects a value then...
2
3098
by: Benedict Teoh | last post by:
I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit...
5
3103
by: Ian Oldbury | last post by:
i have a dropdownlist box which has autopostback set to true. Does anynone know if its possible to obtain the value that was in the dropdownlist prior to the postback? i could obviously store...
2
4637
by: John Blair | last post by:
Hi, I have a dropdownlist in a grid header template - i have autopostback on but when i check the selectedindex in the page_load event (i have a routine which identifies the control that caused...
5
5924
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
1
2081
by: Geoffrey van den Ouden | last post by:
I'm converting this project from ASP.NET 1.1 to 2.0, and the thing I came across is that my dropdownlist no returns the content of the Value property in a correct way. I'm not using a direct...
2
6069
by: Kevin Blount | last post by:
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...
0
7115
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6978
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7190
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7360
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4881
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1392
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
280
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.