Reputation: 185
I have a literal Control in my default.aspx, and i want to access this from my masterpage.When i try to do this,i got null exception error(object reference missing).
Upvotes: 0
Views: 864
Reputation: 241
You can use FindControl
in your master page.
Content page:
<asp:Literal runat="server" ID="myLiteral"></asp:Literal>
And in your master page load (or other place):
protected void Page_Load(object sender, EventArgs e) {
var myLiteral = ContentPlaceHolder1.FindControl("myLiteral");
if (myLiteral != null) {
((Literal)myLiteral).Text = "Hello World!";
}
}
Where ContentPlaceHolder1
is the ID of your placeholder in the master page.
Upvotes: 1