How to use dropdownlist selectedIndexChanged in clientSide and ServerSide

How to use selectedIndexChanged from asp.net dropdown in clientSide and ServerSide?

In clientide, I want to use the javascript funcition function!

<script type="text/javascript"> function changeCursor() { document.body.style.cursor="progress"; } </script> <asp:DropDownList ID="DropDownSubject" runat="server" DataTextField="Word" AutoPostBack="True" OnSelectedIndexChanged="SelectedChange"> </asp:DropDownList> 

SelectedChange is the name of the function in clientide!

Thanks for the help!

+14
javascript c # drop-down-menu
Sep 20
source share
3 answers

Add the client-side function name to the onchange events of the drop-down menu, as shown below:

 <asp:DropDownList ID="DropDownSubject" runat="server" DataTextField="Word" AutoPostBack="True" OnSelectedIndexChanged="SelectedChange" onchange="changeCursor()"> </asp:DropDownList> 
+22
Sep 20
source share

In HTML (.aspx)

 <asp:DropDownList ID="DropDownSubject" runat="server" DataTextField="Word" AutoPostBack="True" OnSelectedIndexChanged="SelectedChange" onchange="YourChangeFun(this);"> </asp:DropDownList> 

In javascript

 <script type="text/javascript"> function YourChangeFun(ddl) { alert(ddl.selectedIndex); } </script> 
+12
Sep 20 '12 at 16:55
source share

First change autopostback = "false" and give onchange = "js function ()" and delete the selected index change event.

+1
Jan 18 '13 at
source share



All Articles