Error Creating Control vs2010 MasterPage

久未见 提交于 2019-12-24 00:02:18

问题


Someone can explain this error?

Error Creating Control - head Object reference not set to an instance of an object.

<%@ 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>

I Think this is a bug of visual studio 2010 in design view. I'not using any event to manipulate session object in the method OnInt(). The "PlaceHolderTopo" is an placeholder in the web user control Topo.ascx. It's work normaly. I Don't have any code inside the content place holder in the page tha inherits from the master page and get this error.

Below is the code of the masterpage:

<%@ 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>

回答1:


You have a bug in your Rodape control at design time.

When you open your page in Design view, it creates an instance of your custom control in Visual Studio's process. Since your website is not actually running, the code in your control is probably accessing some static member which hasn't been initialized.

You should launch a second copy of Visual Studio, attach its debugger to the first copy, set Break on All Exceptions from the Debug menu, and find your bug.



来源:https://stackoverflow.com/questions/3159427/error-creating-control-vs2010-masterpage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!