我的母版页中的自定义控件,是否可以访问主页?
请帮忙! 这是我的代码。
namespace TVSSystem
{
public partial class ControlTVS1 : System.Web.UI.UserControl
{
Page abc;
protected void Page_Load(object sender, EventArgs e)
{
abc = this.Page; //Control: I suposse that I can access all controls of my page
}
protected void Image1_Click(object sender, ImageClickEventArgs e)
{
ContentPlaceHolder cph = (ContentPlaceHolder)abc.FindControl("ContentPlacerHolder1");
TextBox txt = (TextBox)cph.FindControl("TextBox1");
Button btn = (Button)cph.FindControl("Button3");
txt.Visible = true;
btn.Visible = true;
}
}
}
答案 0 :(得分:2)
您可以使用Page
属性访问包含此用户控件的页面(无论您是否将其放在母版页中):
public partial class WebUserControl1 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
var page = this.Page;
...
}
}