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 に答える