Jump Menu (DropDown Menu) in ASP.net. Can someone help me out?

  • Thread starter Miguel Dias Moura
  • Start date
M

Miguel Dias Moura

Hello,

i have a drop down menu in ASP.net with 5 options. I want to redirect to a
certain page when a certain option is selected.
I want to be redirected without having to click a button. Does anyone knows
how to make this?

Thank You,
Miguel
 
B

Bruno Sirianni

<asp:DropDownList /> have AutoPostBack property. If this property is set to
true it automatically when change the List value fire a SelectedIndexChanged
event on Page.

In this method you can switch the DropDownList.SelectedValue and make a
Redirect where you want.

Brun
 
M

Miguel Dias Moura

Hi,

i wrote this script but it's not working as i expected. Can you tell me what
am i doing wrong?

<script runat="server">

Sub Page_Load(Sender As Object, E As EventArgs)
if myselect.AutoPostBack then
Response.Redirect ("http://" &
myselect.items(myselect.SelectedIndex).Value)
end if
End Sub

</script>

Drop Down Menu:

<asp:DropDownList AutoPostBack="true" ID="myselect" runat="server">
<asp:ListItem value="www.bonsalunos.com">item1</asp:ListItem>
<asp:ListItem value="www.sapo.pt">item2</asp:ListItem>
<asp:ListItem value="www.google.com">item3</asp:ListItem>
</asp:DropDownList>

Thanks,
Miguel
 
B

Bruno Sirianni

Try with this :

<script runat=server language=C#>
private void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

}
}
private void DropDownList1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
if (((DropDownList)sender).SelectedValue != "")
Response.Redirect(((DropDownList)sender).SelectedValue);
}

</script>

<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server" OnLoad="Page_Load">
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 101; LEFT: 184px;
POSITION: absolute; TOP: 184px"
runat="server" AutoPostBack="True"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem value="">item0</asp:ListItem>
<asp:ListItem
value="http://www.bonsalunos.com">item1</asp:ListItem>
<asp:ListItem value="http://www.sapo.pt">item2</asp:ListItem>
<asp:ListItem value="http://www.google.com">item3</asp:ListItem>

</asp:DropDownList>
</form>
</body>
 

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,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top