How use selectedIndexChanged dropdownlist in clien

2020-01-31 01:13发布

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!

3条回答
Fickle 薄情
2楼-- · 2020-01-31 02:01

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>
查看更多
Deceive 欺骗
3楼-- · 2020-01-31 02:08

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

查看更多
Ridiculous、
4楼-- · 2020-01-31 02:14

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>
查看更多
登录 后发表回答