asp.net dynamic Add multiple User controls _ Practical Tips

Source: Internet
Author: User
User Control Code:
Code WebControls
Copy Code code as follows:

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 page code:
Code
Copy Code code as follows:

Public partial class WebForm1:System.Web.UI.Page
{
protected voi d Page_Load (object sender, EventArgs e)
{
}
protected void Button1_Click (object sender, EventArgs e) br>{
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.Ar Raylist list = null;
if (session["a"]!= null)
{
List = (ArrayList) session["a"];
}
Else
{
List = new ArrayList ();
}
List. ADD (l);
session["a"] = list;
return list;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.