salman rafiq
salman rafiq

Reputation: 81

i'm in Trouble with Nested Master Page :(

how to use nested Master Pages in Asp.net ? i'm facing an error of nullrefrence exception on every nested master page control? can you please tell me what i'm doing wrong?

on PageLoad Binding a label

secondMasterTesting.Text = "Hello World form Second Master";

here is my base master page top:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage.master.cs" Inherits="BluePumpkin.MasterPage" %> <!DOCTYPE html>

and my nestedMaster Page here from top:

<%@ Master Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="Admin.master.cs" Inherits="BluePumpkin.AdminPanel.Admin" %>

Upvotes: 0

Views: 44

Answers (1)

Aristos
Aristos

Reputation: 66649

Your secondMasterTesting is probably hidden because is either inside ContentPlaceHolder or you call it from some other page than the one the control is registered.

To solve the error try

if(secondMasterTesting != null)
  secondMasterTesting.Text = "Hello World form Second Master";

The code behind is search on belonging page for that control.

Upvotes: 1

Related Questions