日期:2014-05-17 浏览次数:20505 次
public partial class _Default : System.Web.UI.Page { protected Control ctl; string str1; protected void Page_Load(object sender, EventArgs e) { if(IsPostBack) { if (Session["System"] != null) str1 = Session["System"].ToString(); if (ViewState["isLoadControl"] != null && ((bool)ViewState["isLoadControl"]))//再次加载 { this.ctl = this.LoadControl(str1);//加载控件 this.ctl.ID = "TEST"; this.PlaceHolder1.Controls.Add(this.ctl); //在页面上呈现 } } } protected void Button1_Click(object sender, EventArgs e) { BlindHolder("test/test_2.ascx"); } public void BlindHolder(string str) { PlaceHolder1.Controls.Clear(); if (this.PlaceHolder1.Controls.Count == 0) //第一次加载 { this.ctl = this.LoadControl(str); this.ctl.ID = "TEST"; this.PlaceHolder1.Controls.Add(this.ctl); } ViewState["isLoadControl"] = true; Session["System"] = str; } }
public partial class test_test_2 : System.Web.UI.UserControl { string str; protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Label1.Text = "TEST2测试成功!"; } }