Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have to find a Control in an aspx page bound to a master page.

The master page contains:

<asp:ContentPlaceHolder ID="MainContent" runat="server"/>               

The content page contains:

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
</asp:Content>

I added a Table with ID formtable as a child of Content2.

I tried to use the following code to access the Table, but the code returns null:

protected void Ok_Click(object sender, EventArgs e)
{
    Table tblForm = this.FindControl("MainContent").FindControl("formtable") as Table;                 
}

How can I access the Table?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
143 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try this

Table tblForm = this.Master.FindControl("MainContent").FindControl("formtable") as Table; 

Checkout this Control ID Naming in Content Pages for more details


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...