views:

37

answers:

2

Hi everyone,

I have to find a Control(a Table) in an aspx page with master page :

the Master page have this :

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

and int the child page :

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

I insert my Table in the Content2.

I used this code to get it :

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

But it's null !

do you have any idea to resolve this problem ?

Thank you !

A: 

What context are you in when you are trying to do this? Are you in the codebehind of the individual page?

If you are it should be Content1.FindControl("formtable") as Table and that would be it.

Mitchel Sellers
A: 

Try this

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

Checkout this link for more details

Vinay B R