1

I have a master page with a label... When i try to find this label on backend it returns me null... Anyone can help me?

<div class="container">
    <div class="row" runat="server" id="Alert" visible="false">
        <div class="alert alert-danger alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span></button>
            <strong>Atenção! </strong>
            <asp:Label ID="lbAlert" for="Alert" runat="server" />
            <asp:LinkButton ID="lbkbtnAtivar" for="Alert" runat="server" />
        </div>
    </div>
</div>

and backend.

        Label lbAlert = (Label)this.Master.FindControl("lbAlert");
        LinkButton lbkbtnAtivar = (LinkButton)this.Master.FindControl("lbkbtnAtivar");

If anyone know, help me please!! :)

Felipe A.
  • 929
  • 3
  • 12
  • 28

1 Answers1

2

Remove "Master"

Label lbAlert = (Label)this.FindControl("lbAlert");
LinkButton lbkbtnAtivar = (LinkButton)this.FindControl("lbkbtnAtivar");

You are already in the appropriate scope for the class. Therefore, "this" refers to the masterpage.

jdaval
  • 610
  • 5
  • 10
  • I can use Label lbAlert = (Label)Master.FindControl("lbAlert"); too? – Felipe A. Sep 09 '15 at 02:40
  • Sure. "This" refers to the instance and is redundant when using Master. Otherwise, you are calling a parent Master page of the current master page. Which is NULL. – jdaval Sep 09 '15 at 02:46