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

本文标签: caspListBox OnSelectedIndexChanged call javascript function not server side codeStack Overflow