Link to home
Start Free TrialLog in
Avatar of rkneal
rkneal

asked on

OnClick Event in A Select Dropdown Menu (ASP)

Is it possible to have an onClick event fired off when something is selected from a Select dropdown list in ASP?  Similar to how a button when clicked performs an action I would like when an item is selected from a dropdown list that it immediately opens a new page.  This way it does not require the user to select the item from the drop down, then hit a submit button.

this is what I used for one of my buttons.
<input type="button" value="Refresh" onClick="location.href='<%= Me.NewURL.ToString() %>';">

Is there a way to use this method for a dropdown?  Something like
<input type="dropdown" value="Refresh" onClick="location.href='<%= Me.NewURL.ToString() %>';">
Avatar of carlnorrbom
carlnorrbom
Flag of Sweden image

Hi,

You can simply do something like:

<asp:DropDownList ID="ddl" runat="server" OnSelectedIndexChanged="ddl_OnSelectedIndexChanged">
    <asp:ListItem .../>
</asp:DropDownList>

And in code behind:

Protected Sub ddl_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddl.SelectedIndexChanged
    Response.Redirect(Me.NewURL.ToString())
End Sub

/Carl.
ASKER CERTIFIED SOLUTION
Avatar of shankwheat
shankwheat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rkneal
rkneal

ASKER

Shank - What you have does work but I get a prompt when I click an item from the drop down.  The prompt says

"Javascript: A script has requested that a new URL be loaded.  Do you wish to load http://XXX.XX"

This happens on a blackberry browser.  If I click Yes, it opens the page but if I can get fix this prompt then that would be all I need.  Any ideas?
Avatar of rkneal

ASKER

Works to accomplish what I want but I have to find out a way around an annoying prompt.