按需加载两个asp.net UserControl [英] load two asp.net UserControl on Demand
本文介绍了按需加载两个asp.net UserControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi
我希望按需加载两个用户控件
HtmlCode
i want load two user control on demand
HtmlCode
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" UseSubmitBehavior="false" OnClick="Button1_Click" />
<div id='Div_UserControlPlace' enableviewstate="true" runat="server" >
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Button ID="Button2" runat="server" Text="Button" UseSubmitBehavior="false" OnClick="Button2_Click" />
<div id='Div_UserControlPlace2' enableviewstate="true" runat="server" >
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Button2" />
</Triggers>
</asp:UpdatePanel>
aspx.cs
aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Control FeaturedProductUserControl = new Control();
FeaturedProductUserControl = LoadControl("WebUserControl1.ascx");
FeaturedProductUserControl.EnableViewState = true;
Div_UserControlPlace.Controls.Add(FeaturedProductUserControl);
}
protected void Button2_Click(object sender, EventArgs e)
{
Control FeaturedProductUserControl2 = new Control();
FeaturedProductUserControl2 = LoadControl("WebUserControl2.ascx");
FeaturedProductUserControl2.EnableViewState = true;
Div_UserControlPlace2.Controls.Add(FeaturedProductUserControl2);
}
我加载第一个用户控件,点击第一个按钮,一切正常,但是当
i load a first user control with click on first button all thing work properly but when
我点击其他按钮加载第二个UserControl 第一个UserControl dis出现(删除)和第二个用户控制加载
i click on other button for load second UserControl first UserControl dis Appear(Remove) And Second User Control Load
谢谢你
IFA_User
Thanks
IFA_User
推荐答案
正确的论坛是http://forums.asp.net。
The correct forum would be http://forums.asp.net.
这篇关于按需加载两个asp.net UserControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文