williamsandonz
williamsandonz

Reputation: 16420

Can't find control using FindControl

Having trouble getting find control to find something, but it's returning null when the control does exist.

It's being called on an asp:button click (and no fields have display dynamic on them). The controls are labels, and have runat server e.t.c. I'm using Umbraco, was thinking going Page.FindControl might not work /w umbraco because it uses master pages? Here's the code:

<asp:Label ID="Reg_Name_Error" CssClass="error" runat="server" />

if (Page.FindControl("Reg_Name_Error") != null) { }

Upvotes: 3

Views: 2522

Answers (1)

Vishal Patel
Vishal Patel

Reputation: 281

As you are using master page you have to write following code

ContentPlaceHolder content;
content = (ContentPlaceHolder)Master.FindControl("Your Content Place Holder Id");

Then write following code

if (content != null)
        {
            if (content.FindControl("Reg_Name_Error") != null)

Upvotes: 3

Related Questions