...

View Full Version : onChange equivalent for <asp:DropDownList>



CurtWRC
12-14-2006, 03:45 PM
When using the <select> function you can use the 'onChange' attribute to automatically redirect to another page like this:


onChange="if(this.options[this.selectedIndex].value) window.location='/board.aspx?id=1&page='+this.options[this.selectedIndex].value;"


Is there an equivalent attribute for <asp:Dropdownlist> so that I don't need to have a button next to the dropdown list like here: http://www.rallystuff.net/Events.aspx

Brandoe85
12-14-2006, 03:57 PM
I think you want SelectedIndexChanged? Check that out and let us know.

good luck

CurtWRC
12-14-2006, 04:23 PM
I think you want SelectedIndexChanged? Check that out and let us know.

good luck

Ive just tried this, but it didn't work. Nothing happened.


SelectedIndexChanged="window.location='/board.aspx?id=1&page='+this.options[this.selectedIndex].value;"

otaku149
12-14-2006, 04:29 PM
Don't forget to set AutoPostBack to True



<asp:DropDownList ID="seasondpdn" runat="server" OnSelectedIndexChanged="DDListRedirect" AutoPostBack="True">
</asp:DropDownList>




Protected Sub DDListRedirect(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Redirect("/events.aspx?c=" & seasondpdn.SelectedValue)
End Sub

Brandoe85
12-14-2006, 04:29 PM
That's a server side event, I was thinking that's the route you were trying to take.

onchange should work with asp dropdown as well. Try it out.

Good luck;

CurtWRC
12-14-2006, 04:37 PM
Thanks thats exactly what I was after.

Brandoe85, the onChange attribute wouldnt work on the asp.net web control for some reason. Thanks anyway.

otaku149
12-14-2006, 04:47 PM
Both will work:



<asp:DropDownList ID="seasondpdn" runat="server">
</asp:DropDownList>




Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
seasondpdn.Attributes.Add("onchange", "window.location='/Events.aspx?c=' + this.options[this.selectedIndex].value;")
End Sub

RashidaJ
01-02-2007, 05:54 PM
suppose ur dropdownlist 's id is ddlMyList and u want to execute some javascript function on its change from client side then try this:

on page_load in code file use:
ddlMyList.Attributes.Add("OnChange", "MyFunction();")

on page write javascript function as:
<script language='javascript'>
function MyFunction()
{
window.location.href ='/board.aspx?id=1&page='+this.options[this.selectedIndex].value;
}
</script>

Hope ur problem wud be resolved using this method it involves no server side post back



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum