asp.net 动态添加 asp.net 动态添加多个用户控件
人气:0想了解asp.net 动态添加多个用户控件的相关内容吗,在本文为您仔细讲解asp.net 动态添加的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:asp.net,动态添加,下面大家一起来学习吧。
用户控件代码: 代码WebControls
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace xuyuanwang.myControl
{
public partial class Lablexuyuan : System.Web.UI.UserControl
{
string a = "ok";
public string A
{
set
{
a = value;
}
get
{
return a;
}
}
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = A;
}
}
}
aspx页面代码:
代码
复制代码 代码如下:
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
myControl.Lablexuyuan ctl = (myControl.Lablexuyuan)Page.LoadControl("myControl/Lablexuyuan.ascx");
ctl.A = this.TextBox1.Text;
ArrayList list = addl(ctl);
for (int i = 0; i < list.Count; i++)
{
myControl.Lablexuyuan ctl2 = (myControl.Lablexuyuan)list[i];
this.UpdatePanel1.ContentTemplateContainer.Controls.Add(ctl2);
}
}
private System.Collections.ArrayList addl(myControl.Lablexuyuan l)
{
System.Collections.ArrayList list = null;
if (Session["a"] != null)
{
list = (ArrayList)Session["a"];
}
else
{
list = new ArrayList();
}
list.Add(l);
Session["a"] = list;
return list;
}
加载全部内容