You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Bootstrap与UpdatePanel兼容问题:ListView下拉框点击后消失

Fixing Bootstrap-Select Disappearing After UpdatePanel Partial Postback

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

  1. Target Only UpdatePanel Elements
    For better performance, narrow down the selector to only the dropdowns inside your UpdatePanel:
    $('#YourUpdatePanelId .selectpicker').selectpicker('refresh');
    
  2. Verify Script Loading
    In your browser's developer tools console, run $('.selectpicker').selectpicker to confirm the plugin is loaded (it should return a function, not undefined). This ensures your ScriptBundle is working correctly on initial page load.
  3. Avoid Duplicate Initialization
    Make sure you're already initializing bootstrap-select on page load (outside of pageLoad), like this:
    $(document).ready(function() {
        $('.selectpicker').selectpicker();
    });
    

内容的提问来源于stack exchange,提问作者rcs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:58:46