zl程序教程

您现在的位置是:首页 >  后端

当前栏目

asp.net动态添加多个用户控件

NetASP 用户 添加 动态 多个 控件
2023-06-13 09:14:15 时间
用户控件代码:
代码WebControls
复制代码代码如下:

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
namespacexuyuanwang.myControl
{
publicpartialclassLablexuyuan:System.Web.UI.UserControl
{
stringa="ok";
publicstringA
{
set
{
a=value;
}
get
{
returna;
}
}
protectedvoidPage_Load(objectsender,EventArgse)
{
Label1.Text=A;
}
}
}

aspx页面代码:
代码
复制代码代码如下:

publicpartialclassWebForm1:System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
}
protectedvoidButton1_Click(objectsender,EventArgse)
{
myControl.Lablexuyuanctl=(myControl.Lablexuyuan)Page.LoadControl("myControl/Lablexuyuan.ascx");
ctl.A=this.TextBox1.Text;
ArrayListlist=addl(ctl);
for(inti=0;i<list.Count;i++)
{
myControl.Lablexuyuanctl2=(myControl.Lablexuyuan)list[i];
this.UpdatePanel1.ContentTemplateContainer.Controls.Add(ctl2);
}
}
privateSystem.Collections.ArrayListaddl(myControl.Lablexuyuanl)
{
System.Collections.ArrayListlist=null;
if(Session["a"]!=null)
{
list=(ArrayList)Session["a"];
}
else
{
list=newArrayList();
}
list.Add(l);
Session["a"]=list;
returnlist;
}