0

我的 Masterpage 中的自定义控件,可以访问主页吗?

请帮忙!这是我的代码。

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;
        }
    }
}

解决了。 http://forums.asp.net/t/1000865.aspx/1

4

1 回答 1

2

您可以使用该Page属性访问包含此用户控件的页面(无论您是否将其放在母版页中):

public partial class WebUserControl1 : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var page = this.Page;
        ...
    }
}
于 2012-04-15T08:32:56.547 回答