c# - asp:ListBox OnSelectedIndexChanged call javascript function not server side code - Stack Overflow

I am needing to call a javascript function when my asp:ListBox has a selection change rather then runni

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 badges
Add a ment  | 

1 Answer 1

Reset to default 3

Add 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);
    }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745569078a4633571.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信