problem with postback

D

David

Hi,

I have a problem with postback. When the page is postbacked, i want the
second dropdownlist to be visible if the selectedvalue of the first one
="y".
With this code, it remains invisible. What do i wrong here?
Thanks
David

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack=true>
<asp:ListItem>x</asp:ListItem>
<asp:ListItem>y</asp:ListItem>
</asp:DropDownList>

<br /> <br />
<asp:DropDownList ID="DropDownList2" runat="server"
AutoPostBack=true Visible=false>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:DropDownList>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
If Page.IsPostBack Then
If DropDownList1.SelectedValue = "y" Then
DropDownList2.Visible = True
End if
End If
End Sub
 
D

David

Thanks for replying.
I tried the code within this:
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
....
End Sub

but ddl2 still invisible.
I don't understand why the Page.IsPostBack doesn't work ...
 
D

David Wier

I just tried this:

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
If DropDownList1.SelectedValue = "y" Then DropDownList2.Visible = "True"
End Sub

and it worked fine for me

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup
 
D

David

In order to check the AutoPostBack only, i reduced the code to this:
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br /><br />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack=true >
<asp:ListItem>x</asp:ListItem>
<asp:ListItem>y</asp:ListItem>
</asp:DropDownList>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
Label1.Text = "ok"
End If
End Sub

But after having chosen a value in the DDL, the label.text never becomes
"ok".

So AutoPostBack doesn't work??? Or i forget to set a parameter or an option
in web.config or ...?
 
D

David

I have just tested the reduced code with Cassini (included in VWD 2008) and
.... it works.
But when i try it with the normal browser IE 7 (with IIS), it doesn't ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top