2017-08-01 62 views
1

如何防止单击按钮时在updatepanel内回发或更新下拉列表。 我这样做是因为我有Java脚本使ddl成为可搜索的下拉列表。我在更新面板中有几个标签,文本框,gridviews和dropdownlist。当我点击查看按钮dropdownlist回到正常下拉代替搜索下拉。如何防止点击按钮时在updatepanel内回发或更新下拉列表

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> 

回答

2

即使没有完全回发的UpdatePanel内的一切仍然被刷新,并因此失去DOM是进行了修改与jQuery的元素。

您还需要在异步回传之后调用创建可搜索下拉列表的函数。

<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

我已经上传我的Java脚本代码查收吧。我仍然无法解决问题。\ –

+0

看到我的更新... – VDWWD

+0

它的工作!竖起大拇指非常感谢。 –

0

在JavaScript的pageLoad事件中写入JavaScript函数。

它将始终在回发和部分回发中执行。

查找下面的代码为你的函数

function pageLoad() { 
      //This will ensure your code will run all the time 
      CreateDropdown(); 
      InitializeDatePickers(); 
      AssignPlugins(); 

     } 
+0

这是我的javasrcript代码。我怎么能在页面加载事件内部调用它? ' –

+0

您可以尝试下面的代码: Yogesh

相关问题