【问题标题】:i'm in Trouble with Nested Master Page :(我遇到了嵌套母版页的麻烦:(
【发布时间】:2015-11-29 08:09:50
【问题描述】:

如何在 Asp.net 中使用嵌套母版页?我在每个 嵌套母版页 控件上都遇到了 nullrefrence 异常错误?你能告诉我我做错了什么吗?

在PageLoad上绑定一个标签

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

这是我的基础母版页顶部:

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

和我的 nestedMaster 页面从顶部开始:

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

【问题讨论】:

    标签: asp.net master-pages


    【解决方案1】:

    您的secondMasterTesting 可能是隐藏的,因为要么在ContentPlaceHolder 内,要么您从注册控件的页面以外的其他页面调用它。

    解决错误试试

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

    后面的代码是在所属页面上搜索该控件。

    【讨论】:

    • 问题解决了,这是我自己的基本错误!因为我对母版页很陌生......谢谢......
    猜你喜欢
    • 1970-01-01
    • 2013-01-06
    • 1970-01-01
    • 2021-06-06
    • 1970-01-01
    • 2017-08-25
    • 2020-11-02
    • 2010-12-23
    • 1970-01-01
    相关资源
    最近更新 更多