【问题标题】:Error Creating Control vs2010 MasterPage创建控件时出错 vs2010 MasterPage
【发布时间】:2010-07-01 23:51:00
【问题描述】:

谁能解释一下这个错误?

创建控件时出错 - 头 对象引用未设置为对象的实例。

<%@ Page Title="" Language="C#" MasterPageFile="~/Controls/Master1.Master"
 AutoEventWireup="true" CodeBehind="GrupoUsuario.aspx.cs" Inherits="GrupoUsuario" %>

<asp:Content ID="Content1" runat="server" contentplaceholderid="head">
</asp:Content>

我认为这是 Visual Studio 2010 在设计视图中的错误。我没有使用任何事件来操作 OnInt() 方法中的会话对象。 “PlaceHolderTopo”是 Web 用户控件 Topo.ascx 中的占位符。工作正常。我在从母版页继承的页面的内容占位符内没有任何代码并收到此错误。

以下是母版的代码:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="PrincipalSeguranca.Master.cs" Inherits="PrincipalSeguranca" %>
<%@ Register Src="Topo.ascx" TagName="Topo" TagPrefix="uc1" %>
<%@ Register src="MenuAdmin.ascx" TagName="MenuAdmin" TagPrefix="uc2" %>
<%@ Register src="Rodape.ascx" tagname="Rodape" tagprefix="uc3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>Sistema</title>
  <script language="jscript" type="text/javascript" src="Scripts/Geral.js"></script>
  <link rel="shortcut icon" href="../layout/ico/favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" href="../layout/css/styles.css" type="text/css" />
  <link href="../layout/css/menu_tabbed.css" rel="stylesheet" type="text/css" />
  <link rel="stylesheet" href="../layout/css/contents.css" type="text/css" />
</head>

<body>

  <form id="form1" ClientInstanceName="form1" runat="server">
    <uc1:Topo ID="Topo1" runat="server" />
    <div id="corpo">
      <asp:ContentPlaceHolder ID="head" runat="server">
      </asp:ContentPlaceHolder>
    </div>
    <div id="rodape">
      <uc3:Rodape ID="Rodape1" runat="server" />
    </div>
  </form>  
</body>
</html>

【问题讨论】:

    标签: c# asp.net master-pages


    【解决方案1】:

    您的Rodape 控件在设计时存在错误。

    当您在设计视图中打开页面时,它会在 Visual Studio 的进程中创建自定义控件的实例。由于您的网站实际上并未运行,因此您控件中的代码可能正在访问一些尚未初始化的静态成员。

    您应该启动 Visual Studio 的第二个副本,将其调试器附加到第一个副本,在“调试”菜单中设置 Break on All Exceptions,然后找到您的错误。

    【讨论】:

    • 谢谢你,你救了我的命!!!我在接口项目引用的其他项目中发现错误并将执行抛出到接口。我解决问题。谢谢你,兄弟。 asp.net 论坛和 msdn 论坛不帮我。 stackoverflow 中的第一篇文章解决了我的问题。这个网站是帮助开发者的最佳选择。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-31
    • 1970-01-01
    • 2017-11-05
    • 2011-05-15
    • 1970-01-01
    相关资源
    最近更新 更多