I am using Eric Hynds’ jQuery for a multi-select list. I have created the control dynamically in the code behind and can successfully bind to it.
The source would look something like:
<div class="multiselectlist">
<select id="MainContent_List" multiple="multiple" name="ctl00$MainContent$List">
</div>
The dynamic controls are in an update panel. When I hit a button it does a partial postback and it loses the jQuery features associated with it.
I assumed that I would need to “re-register the script” so I did this:
ScriptManager.RegisterClientScriptInclude(this, GetType(), "multiselect", Page.ResolveClientUrl("../../Assets/Scripts/jquery.multiselect.min.js"));
Unfortunately nothing happens. I’m fairly sure that it is the javascript that isn’t run. Am I not registering the javascript correctly?
If my understanding is correct you just need to re-bind the JQuery Multiselect to the
select
control.This is because the content of an
UpdatePanel
is re-rendered every time a partial post occurs, this means that the DOM elements are removed and re-created on every postIn order to accomplish your goal just re-bind the events as follows:
Additionally, you could use the
shortcut
to the function: