Bootstrap与UpdatePanel兼容问题:ListView下拉框点击后消失
Hey there, let's break down why your dropdown is vanishing after clicking the "+" icon in your UpdatePanel, and how to fix it properly:
The Root Cause
When UpdatePanel does a partial postback, it replaces the DOM elements inside it with fresh content from the server. The bootstrap-select plugin was initialized on the original dropdown elements, but those bindings get lost when the DOM is replaced.
Your current approach of reloading the entire script bundle via AJAX is overkill and can cause conflicts (since jQuery/Bootstrap are already loaded on the page). You don't need to re-download the scripts—you just need to re-initialize the plugin on the new DOM elements.
The Solution: Re-Initialize Bootstrap-Select, Not the Whole Bundle
Replace your existing pageLoad script with this simpler, targeted code:
<script type="text/javascript"> function pageLoad(sender, args) { if (args.get_isPartialLoad()) { // Refresh existing bootstrap-select instances $('.selectpicker').selectpicker('refresh'); // If your UpdatePanel is adding NEW dropdowns that weren't there before, // uncomment the line below to initialize them first: // $('.selectpicker').selectpicker(); } } </script>
What This Does
selectpicker('refresh'): This method tells bootstrap-select to re-calculate the position and state of the dropdown, which fixes issues where the dropdown stops working after DOM updates.- The optional
selectpicker()call: Use this only if your partial postback is adding entirely new dropdown elements that weren't present on the initial page load.
Additional Tips
- Target Only UpdatePanel Elements
For better performance, narrow down the selector to only the dropdowns inside your UpdatePanel:$('#YourUpdatePanelId .selectpicker').selectpicker('refresh'); - Verify Script Loading
In your browser's developer tools console, run$('.selectpicker').selectpickerto confirm the plugin is loaded (it should return a function, notundefined). This ensures your ScriptBundle is working correctly on initial page load. - Avoid Duplicate Initialization
Make sure you're already initializing bootstrap-select on page load (outside ofpageLoad), like this:$(document).ready(function() { $('.selectpicker').selectpicker(); });
内容的提问来源于stack exchange,提问作者rcs

