0

I am working with ASP.NET

I have a DropDownList item and in there i have hyperlinks as values. What event must i use in my code behind to redirect the user to that URL when he selects the "eRate" item?

My code

   <asp:DropDownList ID="dropSelect" runat="server" Width="126px">
        <asp:ListItem>Please select</asp:ListItem>
        <asp:ListItem Value="http://www.erate.co.za">eRate</asp:ListItem>
    </asp:DropDownList>

thanks in advance!!

Juergen
  • 12,378
  • 7
  • 39
  • 55
Etienne
  • 7,141
  • 42
  • 108
  • 160

1 Answers1

3

add a onselectedindexchanged to the dropdown like this

OnSelectedIndexChanged="dropSelect_OnSelectedIndexChanged"

then codebehind you can do like this.

protected void dropSelect_OnSelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Redirect(dropSelect.SelectedValue);
    }

you can do some extra null check and all that but this is the basic idea you can use

Dejan.S
  • 18,571
  • 22
  • 69
  • 112
  • Where must i place the OnSelectedIndexChanged="dropSelect_OnSelectedIndexChanged" ?? – Etienne Oct 09 '09 at 08:50
  • @Etienne in the asp control on in your markup i.e. – James Oct 09 '09 at 09:00
  • You might also want to set `AutoPostback="true"` on the ``, otherwise the event is not triggered until the next postback (i.e. a button click. Buttons has AutoPostback set to true as default). – awe Oct 09 '09 at 09:11
  • Thanks, what must i place in my code to have this open in a new window? – Etienne Oct 09 '09 at 09:18
  • You won't be able to do this using Response.Redirect as this is processed on the server side. Here is an answer that resolves this issue http://stackoverflow.com/questions/104601/asp-net-response-redirect-to-new-window – James Oct 09 '09 at 09:42
  • you have to do some javascript solution for that. the very basic one is this below. keep in mind that javascript might not work for everybody so you might consider working with the response.redirect response.write(""); – Dejan.S Oct 09 '09 at 09:48