I am trying to add a label the following way
public partial class _base : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
lblText.Text ="Hello";
}
}
}
The problem is it is telling Object reference not set to an intance of an object. This is the code behind my MasterPage.cs.
<asp:Label ID="lblText" runat="server" Text="Label"></asp:Label>
In master page
Where your code has
you should put
instead. This will make the error go away, because then an actual instance of the label control will be referenced by the
lblTextvariable. But the label will not show up until you also addto your page load event.
Alternatively, you could add the label to your page as @amonteiro suggests. Then you could put it in a location that makes sense for the rest of your application.