[英]Select2 is not working in ASP.Net UserControl
I am using the Select2 plugin examples . 我正在使用Select2插件示例 。 It is working on all pages however it is not working in a usercontrol.
它适用于所有页面,但不适用于用户控件。 I have a usercontrol as below:
我有一个用户控件,如下所示:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SearchPage.ascx.cs" Inherits="SIGORTAPRO.WEB.UC.SearchPage" %>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="../../../js/select2.js"></script>
<link href="../../../Content/css/select2.css" rel="stylesheet" />
<asp:Panel ID="panel" runat="server" Visible="false">
<asp:DropDownList ID="ddlSearchDropdownlist" runat="server"></asp:DropDownList>
</asp:Panel>
(function () {
$("#<%= ddlSearchDropdownlist.ClientID %>").select2();
})();
Main Page as below 主页如下
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<uc1:SearchPage runat="server" ID="SearchPage" />
</ContentTemplate>
</asp:UpdatePanel>
If i load page there is no any error however Select2 is not working. 如果我加载页面,则没有任何错误,但是Select2无法正常工作。 The panel is hidden, however I make it visible if I load page.
该面板是隐藏的,但是如果我加载页面,则使它可见。 What am I missing?
我想念什么?
Visible="false"
means the resultant <div>
and its contents are not rendered (ie the browser literally won't know anything about them because they will not be in the HTML that the browser receives). Visible="false"
表示结果的<div>
及其内容未呈现(即,浏览器实际上不了解它们,因为它们不会出现在浏览器接收的HTML中)。
If you want it to be hidden but still there for your code to deal with, then use style="display:none;"
如果您希望隐藏它,但仍在处理代码的地方,请使用
style="display:none;"
or appropriate class definition. 或适当的类别定义。
For example... 例如...
<asp:Panel ID="panel" runat="server" style="display:none;">
<asp:DropDownList ID="ddlSearchDropdownlist" runat="server"></asp:DropDownList>
</asp:Panel>
Or... 要么...
<style type="text/css">
.myHiddenPanel {
display: none;
}
</style>
<asp:Panel ID="panel" runat="server" CssClass="myHiddenPanel">
<asp:DropDownList ID="ddlSearchDropdownlist" runat="server"></asp:DropDownList>
</asp:Panel>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.