How use selectedIndexChanged from asp.net dropdownlist in clientSide and ServerSide?
In clientside i want call javascript funcition!
<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 a name of function in clientside!
Thanks for help!
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Add your client side function name in onchange events of dropdown like below :
<asp:DropDownList ID="DropDownSubject" runat="server" DataTextField="Word"
AutoPostBack="True" OnSelectedIndexChanged="SelectedChange"
onchange="changeCursor()">
</asp:DropDownList>
Method 2
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>
Method 3
First change autopostback=”false” and give onchange=”js function()” and remove selected index change event.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0