admin管理员组文章数量:1431037
I am needing to call a javascript function when my asp:ListBox has a selection change rather then running some server side code. What I have at the moment is.
<asp:ListBox ID="lbCustomerFolders" runat="server" Width="100%" Height="98%" AutoPostBack="true" OnSelectedIndexChanged="lbCustromerFolders_SelectedIndexChanged"/>
Where the OnSelectedIndexChanged I require that function or something similar to call a javascript function.
I am needing to call a javascript function when my asp:ListBox has a selection change rather then running some server side code. What I have at the moment is.
<asp:ListBox ID="lbCustomerFolders" runat="server" Width="100%" Height="98%" AutoPostBack="true" OnSelectedIndexChanged="lbCustromerFolders_SelectedIndexChanged"/>
Where the OnSelectedIndexChanged I require that function or something similar to call a javascript function.
Share Improve this question asked Feb 13, 2015 at 5:59 Brendan RussoBrendan Russo 1763 silver badges11 bronze badges1 Answer
Reset to default 3Add on change event in your control lie I have added in following example. Notice that there are onchange as well as OnSelectedIndexChanged event there on the ListBox so on the selection change event both JavaScript and server side event is going to get called.
In your case change would be data which you are providing.
<asp:ListBox ID="lbCustomerFolders" runat="server" Width="9%" Height="98%" onchange="YourChangeEventJS(this)" AutoPostBack="true" OnSelectedIndexChanged="lbCustomerFolders_SelectedIndexChanged">
<asp:ListItem Text="Red" Value="#FF0000" Selected="True" />
<asp:ListItem Text="Blue" Value="#0000FF" />
<asp:ListItem Text="Green" Value="#008000" />
</asp:ListBox>
Following is script should be there on your page
<script type="text/javascript">
function YourChangeEventJS(ddl) {
alert(ddl.selectedIndex);
}
本文标签: caspListBox OnSelectedIndexChanged call javascript function not server side codeStack Overflow
版权声明:本文标题:c# - asp:ListBox OnSelectedIndexChanged call javascript function not server side code - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745569077a2663937.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论