我要在页面中动态加载一些用户控件,每个用户控件都是一个独立的逻辑单元,我给他们每一个都增加属性便于对外访问,
比如:
public partial class WebUserControl1 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
this.strSql = this.textbox1.text + this.text2.text + ... ;
} /// <summary>
/// 公共成员
/// </summary>
public string strSql;
}把他们加载在页面的placeholder中,
protected void Page_Load(object sender, EventArgs e)
{
if(!this.ispostback)
{
this.LoadControl("WebUserControl1.ascx")
this.LoadControl("WebUserControl2.ascx")
this.LoadControl("WebUserControl3.ascx")
}
else
{
//怎样在页面回发的时候取得控件的公共成员的值呢,this.placeholder.controls.count = 0
}
}
怎么取呢
比如:
public partial class WebUserControl1 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
this.strSql = this.textbox1.text + this.text2.text + ... ;
} /// <summary>
/// 公共成员
/// </summary>
public string strSql;
}把他们加载在页面的placeholder中,
protected void Page_Load(object sender, EventArgs e)
{
if(!this.ispostback)
{
this.LoadControl("WebUserControl1.ascx")
this.LoadControl("WebUserControl2.ascx")
this.LoadControl("WebUserControl3.ascx")
}
else
{
//怎样在页面回发的时候取得控件的公共成员的值呢,this.placeholder.controls.count = 0
}
}
怎么取呢
解决方案 »
- 请教一个TreeView问题
- 页面远程访问有时出错,但vs程序可以
- fckeditor 404错误
- InnerHtml和InnerText
- win7 下VS2005 运行aspx, 关闭IE8 老是再弹出来一次
- 在线紧急求助怎么样在DATAGRID里使用递归。
- 谁知道Visio for Enterprise Architects 哪里能够下载?
- 求救:刚装好的系统,SQL2000,.NET都以装好,运行没有问题,但重启后报错
- C# 如何写访问windows共享文件判断用户名密码的权限提供指定的程序功能
- 怎样在C#中 中断Webservice返回???
- IE6兼容RSS问题!
- WINDOWS SERVER 2003 SP2 导致ASP.NET 1.1下的FORM不能提交
//在MyControl.ascx用户控件里 建一个属性
public string UserName
{
//可改成其他控件
get { return TextBox1.Text; }
set { TextBox1.Text = value; }
}//在使用页面重写OnInit方法protected override void OnInit(EventArgs e)
{
MyControl control = (MyControl)this.LoadControl("MyControl.ascx");
control.ID = "myC";
form1.Controls.Add(control);//from1可改成其他控件
}//获取
MyControl con = (MyControl)form1.FindControl("myC");
if (con != null)
{
Response.Write(con.UserName);
}
public partial class WebUserControl1 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
this.s = this.tb.Text;
} private string _s; public string s
{
get { return this._s; }
set { this._s = value; }
}
}调用页:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
{
WebUserControl1 wu = (WebUserControl1)this.ph.FindControl("symbol");
string sss = wu.s;
}
} protected override void OnInit(EventArgs e)
{
base.OnInit(e); WebUserControl1 wu = (WebUserControl1)this.LoadControl("WebUserControl1.ascx"); wu.ID = "symbol"; this.ph.Controls.Add(wu);
}
}
{
get{string.IsNullOrEmpty(ViewState["UserName"].ToString())?"":ViewState["UserName"].ToString();}
set{ViewState["UserName"]=value;}
}