How to prevent a dropdownlist from postback or updating inside an updatepanel when button is clicked

后端 未结 2 1429
慢半拍i
慢半拍i 2021-01-23 17:48

How to prevent a dropdownlist from postback or updating inside an updatepanel when button is clicked. I am doing this because i have java script to make ddl a searchable dropdow

相关标签:
2条回答
  • 2021-01-23 17:56

    Even though there is no full PostBack, everything inside the UpdatePanel still gets refreshed and so the DOM loses the elements that were modified with jquery.

    You need to call the function that created the searchable dropdownlists after a async PostBack also.

    <script type="text/javascript">
        $(document).ready(function () {
            createSearchDropDown();
        });
    
        var prm = Sys.WebForms.PageRequestManager.getInstance();
    
        prm.add_endRequest(function () {
            createSearchDropDown();
        });
    
        function createSearchDropDown() {
            $(".chzn-select").chosen(); 
            $(".chzn-select-deselect").chosen({ allow_single_deselect: true });
        }
    </script>
    
    0 讨论(0)
  • 2021-01-23 17:58

    Write your javascript function in pageLoad event of javascript.

    It will always be executed in postback as well as partial postbacks also.

    Find below code for your functions

     function pageLoad() {
                 //This will ensure your code will run all the time
                 CreateDropdown();
                 InitializeDatePickers();
                 AssignPlugins();
    
            }
    
    0 讨论(0)
提交回复
热议问题