473,387 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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
2 6066
Hello Kevin,

when u use visible=fasle your control is out from the list of Page elements.
To keep your control but hide it use object.style.visibility, (if doesn't
mix up with style.display property)

KBI have a test script right now that I'm fighting with. The idea is
KBto "simply" have an aspx page with 3 panels, to show 3 "different"
KBforms and then a 4th panel to show the results of processing these
KBforms.
KB>
KBOne of the panels will contain DropDownLists, who's items are
KBdynamically added in terms of text and values. For example, one of
KBthese lists will be languages. I want to list presented in the
KBlanguage of the person viewing it, i.e. if they are visiting out
KBFrench website, they see "Français", but if they are on our UK
KBwebsite they see "French". The value will always be "French".
KB>
KBThe problem I'm find is that when the panel with the DropDownList is
KBnot visible, then I cannot access the .Text property of the list. In
KBthe code below, I have a DropDownList called "testList", and right
KBat the end of the code I do a Response.Write to show testList.Text;
KBbut this will only work when panel3.Visible = true.
KB>
KBNaturally this isn't going to work, as if my 3 forms (in panels 1, 2
KB& 3) are going to work properly, they must be hidden until required,
KBand once the form fields on panel3 are completed, they should all be
KBhidden.
KB>
KBIs there any way to change the code below to make this work even if
KBthe panel holding the DropDownList is hidden?
KB>
KBMany thanks
KB>
KBHere's the code:
KB>
KB<body>
KB<script runat="server">
KBpublic string usernameString = string.Empty;
KBprivate void Page_Load(object sender, EventArgs e)
KB{
KBusernameString = Request["username"];
KBhideAllPanels();
KB>
KBif (!IsPostBack)
KB{
KBpanel1.Visible = true;
KB}
KB}
KBprivate void button_click(object sender,
KBSystem.Web.UI.WebControls.CommandEventArgs e)
KB{
KBif (e.CommandName == "show_panel2")
KB{
KBpanel2.Visible = true;
KB}
KBelse if(e.CommandName == "show_panel3")
KB{
KBpanel3.Visible = true;
KB}
KBelse if(e.CommandName == "show_panel4")
KB{
KBpanel3.Visible = false;
KBpanel4.Visible = true;
KB}
KB}
KBprivate void hideAllPanels() {
KBpanel1.Visible = false;
KBpanel2.Visible = false;
KBpanel3.Visible = false;
KBpanel4.Visible = false;
KB}
KB</script>
KB<%
KB%>
KB<form action="" method="post" name="pageform" id="pageform"
KBrunat="server">
KB<asp:Panel ID="panel1" runat="server" Wrap="true">
KB<h2>Panel 1</h2>
KB<asp:TextBox ID="username" runat="server" />
KB<asp:RequiredFieldValidator id="RequiredFieldValidator1"
KBCssClass="smallFontRed" runat="server" Height="8px"
KBErrorMessage="This
KBfield is required"
KBControlToValidate="username"></asp:RequiredFieldValidator>
KB<asp:Button ID="show_panel2" CommandName="show_panel2"
KBOnCommand="button_click" runat="server" Text="Next >" />
KB</asp:Panel>
KB<asp:Panel ID="panel2" runat="server" Wrap="true">
KB<h2>Panel 2</h2>
KB<asp:CheckBox ID="textCheckBox" runat="server" Value="as test"
KBText="booyah" />
KB<asp:Button ID="show_panel3" CommandName="show_panel3"
KBOnCommand="button_click" runat="server" Text="Next >" />
KB</asp:Panel>
KB<asp:Panel ID="panel3" runat="server" Wrap="true">
KB<h2>Panel 3</h2>
KB<%
KBListItem languageSelectItem = new
KBListItem("TextToAppear","ValueToUse");
KBtextList.Items.Add(languageSelectItem);
KB%>
KB<asp:DropDownList ID="textList" runat="server"
KBEnableViewState="false"></asp:DropDownList>
KB<asp:Button ID="show_panel4" CommandName="show_panel4"
KBOnCommand="button_click" runat="server" Text="Finish" />
KB</asp:Panel>
KB<asp:Panel ID="panel4" runat="server" Wrap="true">
KB<%
KBResponse.Write(username.Text + " - " + textCheckBox.Text + " - " +
KBtextList.Text);
KB%>
KB</asp:Panel>
KB</form>
KB</body>
KB>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Sep 6 '06 #2
Michael,

Thanks for the response.

Do you have an example of this anywhere?

right now my Page_Load and hideAllPanels() method use:

panel1.Visible = true;

how would I change this?

panel1.style.visibility = none; ??

Kevin

Michael Nemtsev wrote:
Hello Kevin,

when u use visible=fasle your control is out from the list of Page
elements.
To keep your control but hide it use object.style.visibility, (if
doesn't mix up with style.display property)

KBI have a test script right now that I'm fighting with. The idea is
KBto "simply" have an aspx page with 3 panels, to show 3 "different"
KBforms and then a 4th panel to show the results of processing these
KBforms.
KBKBOne of the panels will contain DropDownLists, who's items are
KBdynamically added in terms of text and values. For example, one of
KBthese lists will be languages. I want to list presented in the
KBlanguage of the person viewing it, i.e. if they are visiting out
KBFrench website, they see "Français", but if they are on our UK
KBwebsite they see "French". The value will always be "French".
KBKBThe problem I'm find is that when the panel with the
DropDownList is
KBnot visible, then I cannot access the .Text property of the list. In
KBthe code below, I have a DropDownList called "testList", and right
KBat the end of the code I do a Response.Write to show testList.Text;
KBbut this will only work when panel3.Visible = true.
KBKBNaturally this isn't going to work, as if my 3 forms (in panels
1, 2
KB& 3) are going to work properly, they must be hidden until required,
KBand once the form fields on panel3 are completed, they should all be
KBhidden.
KBKBIs there any way to change the code below to make this work even if
KBthe panel holding the DropDownList is hidden?
KBKBMany thanks
KBKBHere's the code:
KBKB<body>
KB<script runat="server">
KBpublic string usernameString = string.Empty;
KBprivate void Page_Load(object sender, EventArgs e)
KB{
KBusernameString = Request["username"];
KBhideAllPanels();
KBKBif (!IsPostBack)
KB{
KBpanel1.Visible = true;
KB}
KB}
KBprivate void button_click(object sender,
KBSystem.Web.UI.WebControls.CommandEventArgs e)
KB{
KBif (e.CommandName == "show_panel2")
KB{
KBpanel2.Visible = true;
KB}
KBelse if(e.CommandName == "show_panel3")
KB{
KBpanel3.Visible = true;
KB}
KBelse if(e.CommandName == "show_panel4")
KB{
KBpanel3.Visible = false;
KBpanel4.Visible = true;
KB}
KB}
KBprivate void hideAllPanels() {
KBpanel1.Visible = false;
KBpanel2.Visible = false;
KBpanel3.Visible = false;
KBpanel4.Visible = false;
KB}
KB</script>
KB<%
KB%>
KB<form action="" method="post" name="pageform" id="pageform"
KBrunat="server">
KB<asp:Panel ID="panel1" runat="server" Wrap="true">
KB<h2>Panel 1</h2>
KB<asp:TextBox ID="username" runat="server" />
KB<asp:RequiredFieldValidator id="RequiredFieldValidator1"
KBCssClass="smallFontRed" runat="server" Height="8px"
KBErrorMessage="This
KBfield is required"
KBControlToValidate="username"></asp:RequiredFieldValidator>
KB<asp:Button ID="show_panel2" CommandName="show_panel2"
KBOnCommand="button_click" runat="server" Text="Next >" />
KB</asp:Panel>
KB<asp:Panel ID="panel2" runat="server" Wrap="true">
KB<h2>Panel 2</h2>
KB<asp:CheckBox ID="textCheckBox" runat="server" Value="as test"
KBText="booyah" />
KB<asp:Button ID="show_panel3" CommandName="show_panel3"
KBOnCommand="button_click" runat="server" Text="Next >" />
KB</asp:Panel>
KB<asp:Panel ID="panel3" runat="server" Wrap="true">
KB<h2>Panel 3</h2>
KB<%
KBListItem languageSelectItem = new
KBListItem("TextToAppear","ValueToUse");
KBtextList.Items.Add(languageSelectItem);
KB%>
KB<asp:DropDownList ID="textList" runat="server"
KBEnableViewState="false"></asp:DropDownList>
KB<asp:Button ID="show_panel4" CommandName="show_panel4"
KBOnCommand="button_click" runat="server" Text="Finish" />
KB</asp:Panel>
KB<asp:Panel ID="panel4" runat="server" Wrap="true">
KB<%
KBResponse.Write(username.Text + " - " + textCheckBox.Text + " - " +
KBtextList.Text);
KB%>
KB</asp:Panel>
KB</form>
KB</body>
KB---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche

Sep 6 '06 #3

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

Similar topics

1
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
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
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
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
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
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
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
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...
1
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.