Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
378 views
in Technique[技术] by (71.8m points)

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

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 dropdownlist. i have a few labels, textboxes, gridviews and dropdownlist inside an update panel. when i click view button dropdownlist turns back into normal dropdown insteads of searchable dropdown.

Simple DDL Searchable DDL

<div>
    <asp:DropDownList ID="ddlSector" runat="server" Width="150px"></asp:DropDownList>
    <asp:DropDownList ID="ddlCity" runat="server" Width="150px"></asp:DropDownList>
    <asp:TextBox ID="txtStdID" runat="server" Width="92px" MaxLength="5"></asp:TextBox>
    <asp:Button ID="btnView" runat="server" Text="View" onclick="btnView_Click" AccessKey="V"/>
<table>
    <tr><td><b>Qualification</b></td><td><b>Exemption Type</b></td></tr>
    <tr>              
    <td><asp:DropDownList ID="ddlQualification" class="chzn-select" runat="server" Width="225px" onselectedindexchanged="ddlQualification_SelectedIndexChanged" 
    AutoPostBack="false"></asp:DropDownList></td>
    <td>
    <asp:DropDownList ID="ddlExemType" runat="server" Width="225px">
    </asp:DropDownList></td>        
    </tr>
</table>
</div>
<script src="../Searchable DDL/jquery.min.js"type="text/javascript"></script>  
<script src="../Searchable DDL/chosen.jquery.js"type="text/javascript"></script>  
<script type="text/javascript">
     $(".chzn-select").chosen(); 
 $(".chzn-select-deselect").chosen({ allow_single_deselect: true });</script>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...