我在div中的一个页面中有四种不同类型的usercontorls one.ascx two.ascx three.ascx four.ascx
像这样<%@ Page Language="C#" MasterPageFile="~/MasterPages/template.master" AutoEventWireup="true"CodeFile="ViewCertificateMaster.aspx.cs" Inherits="Pages_ViewCertificateMaster" %>
<%@ Register Src="../Controls/one.ascx" TagPrefix="uc1" TagName="one" %>
<%@ Register Src="../Controls/two.ascx" TagPrefix="uc2" TagName="two" %>
<%@ Register Src="../Controls/three.ascx" TagPrefix="uc3" TagName="three" %>
<%@ Register Src="../Controls/four.ascx" TagPrefix="uc4" TagName="four" %>
<asp:Content ID="Content1" ContentPlaceHolderID="phBody" Runat="Server">
......
............
............
some controls(button and dropdown list)
<table border="0">
<tr>
<td colspan="3">
<div class="content_grid" style="border:0px solid black;width:100%;">
<div style="width: 100%; visibility:hidden;" runat="server" id="divViewMyCerts">
<uc1:one runat="server" ID="one" />
<uc2:two runat="server" ID="two" />
<uc3:three runat="server" ID="three" />
<uc4:four runat="server" ID="four" />
</div>
</div>
</td>
</tr>
</table>
然后在代码中
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
UserControl myAOSUsrControl = Page.LoadControl("../Controls/one.ascx") as UserControl;
divViewMyCerts.Controls.Add(myAOSUsrControl);
divViewMyCerts.Visible = true;
}
}
我在页面加载中遇到问题...我只想加载一个(one.ascx)
的用户控件但我能够看到所有加载的用户控件,并且由于一次加载了四个用户控件,因此需要花费大量时间来加载页面...
这不是我想要的,我只想在页面加载时加载一个用户控件...
如何解决此问题,一次只加载一个用户控件..... 任何人都知道如何做到这一点,这对我来说非常有用
非常感谢...
答案 0 :(得分:1)
首先,您需要从页面中删除四个用户控件。同时删除可见性:隐藏的样式可以添加属性visible =&#34; false&#34;因为你在代码中将它设置为true,所以为了div。 然后使用您已有的代码,但删除!IsPostBack
<%@ Page Language="C#" MasterPageFile="~/MasterPages/template.master" AutoEventWireup="true"CodeFile="ViewCertificateMaster.aspx.cs" Inherits="Pages_ViewCertificateMaster" %>
<asp:Content ID="Content1" ContentPlaceHolderID="phBody" Runat="Server">
......
............
............
some controls(button and dropdown list)
<table border="0">
<tr>
<td colspan="3">
<div class="content_grid" style="border:0px solid black;width:100%;">
<div style="width: 100%;" runat="server" id="divViewMyCerts">
</div>
</div>
</td>
</tr>
</table>