我知道了 用HtmlForm的Parent属性,然后转换类型即可 在用户控件中这么写 public class UserCtrl : System.Web.UI.UserControl { protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.Button btnGo; private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 this.Label1.Text = "哈哈"; HtmlForm form = this.Parent as HtmlForm; System.Web.UI.Page page = form.Page; WebForm p = page as WebForm; this.Label1.Text = p.lblName.Text; } }
转之前最好先判断一下: if(form is HtmlForm){ HtmlForm form = (HtmlForm)this.Parent; } 不知道转类型用(HtmlForm)this.Parent转好还是this.Parent as HtmlForm转好^_^
推荐popcorn的做法,转换之前进行判断转换类型用 (HtmlForm)this.Parent
你应该在用户控件中用属性控制 usercontrol public property aa() as integer set() get() end property btn_click 事件中 select case aa case 1 do something1 case 2 do something2 case else 'not define ' end select在 你的页面web.aspx page_load uc1.aa=1 即可!ok!
用HtmlForm的Parent属性,然后转换类型即可
在用户控件中这么写
public class UserCtrl : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button btnGo; private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
this.Label1.Text = "哈哈";
HtmlForm form = this.Parent as HtmlForm;
System.Web.UI.Page page = form.Page; WebForm p = page as WebForm;
this.Label1.Text = p.lblName.Text;
}
}
if(form is HtmlForm){
HtmlForm form = (HtmlForm)this.Parent;
}
不知道转类型用(HtmlForm)this.Parent转好还是this.Parent as HtmlForm转好^_^
usercontrol
public property aa() as integer
set()
get()
end property
btn_click 事件中
select case aa
case 1
do something1
case 2
do something2
case else
'not define '
end select在 你的页面web.aspx
page_load
uc1.aa=1
即可!ok!