Drop Down List and AutoPostBack. Really urgent. Thank You Very Much

  • Thread starter Miguel Dias Moura
  • Start date
M

Miguel Dias Moura

Hello,

I have a Drop Down List with 3 options. I want to redirect to a new page
when an options is selected. I don't want to use a button. The redirection
should be fired when the option is selected.

I have an ASP.net / VB page with a Drop Down List named "my select" as
follows:

<asp:DropDownList AutoPostBack="true" ID="myselect" runat="server">
<asp:ListItem value="www.google.com">Google</asp:ListItem>
<asp:ListItem value="www.yahoo.com">Yahoo</asp:ListItem>
<asp:ListItem value="www.macromedia.com">Macromedia</asp:ListItem>
</asp:DropDownList>

Then i have this script:

<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>

I looked in the .net and tryied several options but until now i wasn't able
to make it work

This seems really simple. I don't know what is going on and i need to
deliver this as soon as possible. Can you help me?

Thank You,
Miguel
 
R

Rajiv R

Hi Miguel,

Use the OnSelectedIndexChanged event of dropdownlist.
<asp:DropDownList AutoPostBack="true" ID="myselect" runat="server" OnSelectedIndexChanged="myselect_Change">
<asp:ListItem value="www.google.com">Google</asp:ListItem>
<asp:ListItem value="www.yahoo.com">Yahoo</asp:ListItem>
<asp:ListItem
value="www.macromedia.com">Macromedia said:
</asp:DropDownList>

then you can write the handler as
void myselect_Change(Object sender, EventArgs e) {

}
 
B

Bruno Sirianni

There was already a response in :

03/04/2004 -- Re: Jump Menu (DropDown Menu) in ASP.net. Can someone help
me out?


<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="">select one...</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,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top