PC Review


Reply
Thread Tools Rate Thread

cannot get value of DropDownList from postback

 
 
Kevin Blount
Guest
Posts: n/a
 
      6th Sep 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">
<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);
%>
<aspropDownList ID="textList" runat="server"
EnableViewState="false"></aspropDownList>
<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>
 
Reply With Quote
 
 
 
 
Michael Nemtsev
Guest
Posts: n/a
 
      6th Sep 2006
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)

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


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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Dynamic dropdownlist and postBack ... Francois Microsoft ASP .NET 2 17th Sep 2007 06:34 PM
dropdownlist postback not firing =?iso-8859-1?B?R2VhcvNpZA==?= Microsoft Dot NET 1 5th Mar 2007 02:02 PM
dropdownlist postback not firing =?iso-8859-1?B?R2VhcvNpZA==?= Microsoft ASP .NET 5 5th Mar 2007 01:05 PM
cannot get value of dropdownlist from postback Kevin Blount Microsoft ASP .NET 1 7th Sep 2006 02:02 AM
DropDownlist PostBack Question Patrick Olurotimi Ige Microsoft ASP .NET 1 27th May 2005 09:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:47 AM.