Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post

    onChange equivalent for <asp:DropDownList>

    When using the <select> function you can use the 'onChange' attribute to automatically redirect to another page like this:
    Code:
    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 <aspropdownlist> so that I don't need to have a button next to the dropdown list like here: http://www.rallystuff.net/Events.aspx

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    I think you want SelectedIndexChanged? Check that out and let us know.

    good luck

  • #3
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Brandoe85 View Post
    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.

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

  • #4
    Regular Coder
    Join Date
    May 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Don't forget to set AutoPostBack to True

    Code:
    <asp:DropDownList ID="seasondpdn" runat="server" OnSelectedIndexChanged="DDListRedirect" AutoPostBack="True">
    </asp:DropDownList>
    Code:
    Protected Sub DDListRedirect(ByVal sender As Object, ByVal e As System.EventArgs)
    	Response.Redirect("/events.aspx?c=" & seasondpdn.SelectedValue)
    End Sub

  • #5
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    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;

  • #6
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Thanks thats exactly what I was after.

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

  • #7
    Regular Coder
    Join Date
    May 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Both will work:

    Code:
    <asp:DropDownList ID="seasondpdn" runat="server">
    </asp:DropDownList>
    Code:
    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

  • #8
    New to the CF scene
    Join Date
    Jan 2007
    Location
    Islamabad
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •