简体   繁体   中英

Client side & server side at the same event (onselectedindexchanged)

I have this drop down list. is it possible to call a javascript function and the server side function at the same time from the onselectedindexchanged event?

<asp:DropDownList ID="drpPartGroup" 
                  runat="server" 
                  Height="19px" 
                  Width="169px" 
                  AutoPostBack="True" 
                  onselectedindexchanged="drpPartGroup_SelectedIndexChanged">
</asp:DropDownList>

Thanks.

I think this might help. I had something similar with a search form that had a couple of related DropDownLists in an UpdatePanel. A reset button was wired to a JavaScript function which cleared all text fields, etc on the client side. I also needed to reset the related DropDownLists so that a default value was selected for the first DropDownList and the related items were updated in the second DropDownList based on the default value.

Basically, my client-side JavaScript function reset all the fields, including the first DropDownList and then called the .onchange() event on the first DropDownList.

document.getElementById('yourDropDownListClientID').onchange();

You need to develop an API on the server-side and use AJAX to communicate back with it (look into guidelines for RESTful APIs) at the same time you are firing the client-side function. JavaScript can't straight up ask the server to execute a function.

Drop down lists are a bit too dynamic for a solution like this though, I can't think of a way to do anything involving server-side communication with a select box that won't lead to terrible UX. You might want to rethink whatever you are doing entirely.

Yes, but you must handle the postback manually...

See this article which covers this extremely well. http://msdn.microsoft.com/en-us/library/aa479302.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM