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>
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.
Related
I'm using visual studio 2010 asp.net website.
I made an aspx. page called forgetpassword.aspx and added a button with the codes
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("company.aspx");
}
I even tried:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("company.aspx", true);
}
However, the page remains the same, the button is unable to redirect to company.aspx. I suspect there could be something wrong with my master page, but I am not sure. Please advise!
Here is my master page:
<%# Master Language="C#" AutoEventWireup="true" CodeFile="Master.master.cs" Inherits="Master" %>
<!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> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title>Home | Triangle</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/font-awesome.min.css" rel="stylesheet">
<link href="css/animate.min.css" rel="stylesheet">
<link href="css/lightbox.css" rel="stylesheet">
<link href="css/main.css" rel="stylesheet">
<link href="css/responsive.css" rel="stylesheet">
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
<link rel="shortcut icon" href="images/ico/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="images/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="images/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="images/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="images/ico/apple-touch-icon-57-precomposed.png"></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body></body>
</html>
Here is the source view (html) of my forgetpassword.aspx page:
<%# Page Title="" Language="C#" MasterPageFile="~/Master.master" AutoEventWireup="true" CodeFile="forgetpassword.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</asp:Content>
You might need to specify the path, as the way shown in MasterPageFile="~/Master.master".
Response.Redirect("~/company.aspx");
EDIT
You need to use same ContentPlaceHolder ID across all the files, by default it is MainContent.
<asp:ContentPlaceHolder id="MainContent" runat="server">
</asp:ContentPlaceHolder>
And also make sure to place your Button inside a form.
<form action="/" method="post" runat="server">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</form>
Now the redirect should work.
redirect should take a url as a parameter however you are only passing a string "company.aspx". Please try this
Response.Redirect(~/(path)/company.aspx);
Replace path with correct file path in your project
If it is just a redirect use
PostBackUrl="company.aspx"
like
<asp:Button ID="Button1" runat="server" Text="Button" PostBackUrl="company.aspx"/>
This will avoid need of calling event from server side.
Try this
protected void Button1_Click(object sender, EventArgs e)
{
if (Response.IsClientConnected)
{
// If still connected, redirect
// to another page.
Response.Redirect("company.aspx", false);
}
}
https://msdn.microsoft.com/en-us/library/a8wa7sdt(v=vs.110).aspx
I want to create a tag prefix for controls in System.Web assembly.
<%# Page Language="C#" CodeBehind="SimpleCustomControl.aspx.cs" Inherits="SimpleCustomControl" %>
<%# Register TagPrefix="CC" Namespace="System.Web.UI.WebControls" Assembly="System.Web" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<CC:TextBox runat="server"></CC:TextBox>
</div>
</form>
</body>
</html>
But getting "Unrecognized tag prefix or device filter CC. Can not resolve symbol CC" error in VS. And no autocomplete is available after entering <CC:.
Is it possible to register such kind of tag prefix for standard controls?
I am facing this issue in my asp.net application when using update panel. The error only with IE9 and for other browser application works fine. For debuging purpose and to conclude the issue only when using update panel I created a sample asp.net web site.
ASPX
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager runat="server" />
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Button ID="Button1" Text="Click Me" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
When I click on the button, I get the following JS error.
The JS error is
From IE's F12 developer tool,
SCRIPT5007: Unable to get value of the property 'tagName': object is null or undefined
frameTracker.js, line 2 character 395
From Visual Studio 2012,
But when I remove the update panel, the JS error is no longer.
Any idea to solve this problem?
Add following line in <head>
<meta http-equiv="X-UA-Compatible" content="IE=8;FF=3;OtherUA=4" />
OR
<meta http-equiv="X-UA-Compatible" content="IE=9;FF=3;OtherUA=4" />
OR
<meta http-equiv="X-UA-Compatible" content="IE=Edge" /> // is will always be rendered in IE's latest and greatest mode
I'm trying to access User.Identity from my master page so I can figure out which user is logged in, however I can't get it to work. If I import System.Security.Principal in my master page it makes no difference:
<%# Import Namespace="System.Security.Principal" %>
I can access it fine if I try within a Controller.
Any idea what I need to do?
What about through HttpContext.Current.User.Identity?
<%=HttpContext.Current.User.Identity.Name %> Will display the current users name
HttpContext.Current.User will get the IPrincipal object.
Here is a master page that only displays the Username in the title:
<%# Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>
<asp:ContentPlaceHolder ID="TitleContent" runat="server" />
</title>
<link href="../../Content/Style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="page">
<div id="header">
<div id="title">
<h1 id="maintitle">
<%=HttpContext.Current.User.Identity.Name %>
</h1>
</div>
</div>
<div id="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</div>
</div>
</body>
</html>
I think Its Work
HttpContext.Current.User.Identity.Name.ToString()
or
Page.User.Identity.Name.ToString()
You can use HttpContext.Current.User.Name but you need to remember that the Master Page code is executed only after the slave page code. So you can use this variable as long as you are not performing any security logic in the master page.
You can get this from:
Context.User.Identity.Name
I have two master pages and a content page. On my local machine this code works, but once I uploaded to the server I got the following error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1061: 'System.Web.UI.MasterPage' does not contain a definition for 'DivWidth' and no extension method 'DivWidth' accepting a first argument of type 'System.Web.UI.MasterPage' could be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 84:
Line 85:
Line 86: this.Master.Master.DivWidth = 955;
Line 87: SimpleElementCollection restrictedIds = new SimpleElementCollection();
Line 88: restrictedIds.Add(new SimpleElement(priceModifierPriceTypeId));
Source File: c:\Inetpub\testsite\shop\Default.aspx.cs Line: 86
Base Masterpage cocde:
public partial class global : System.Web.UI.MasterPage
{
public int DivWidth { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
SetBodyClass();
if (DivWidth < 1)
{
DivWidth = 768;
}
}
Base Masterpage aspx:
<%# Master Language="C#" AutoEventWireup="true" CodeFile="global.master.cs" Inherits="global" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US" dir="ltr">
<head id="Head1" runat="server" dir="ltr" lang="en-us" profile="http://dublincore.org/documents/dcq-html/">
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>page title</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="content-type" content="en-US" />
<meta http-equiv="content-language" content="en-us" />
<link rel="Bookmark" href="#content" title="Page Content" type="text/html" />
<link rel="Bookmark" href="#primary-navigation" title="Site Navigation" type="text/html" />
<link href="css/screen/global.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/print/print.css" rel="stylesheet" type="text/css" media="print" />
<script src="<%=ResolveUrl("~/javascript/jquery-1.2.6.min.js")%>" type="text/javascript"></script>
<script src="<%=ResolveUrl("~/javascript/jquery.clearonfocus.js")%>" type="text/javascript"></script>
<script src="<%=ResolveUrl("~/javascript/modalControl.js")%>" type="text/javascript"></script>
<asp:ContentPlaceHolder ID="headPlaceholder" runat="server" />
<!--[if IE]><link href="css/screen/ie/ie.css" rel="stylesheet" type="text/css" media="screen" /><![endif]-->
<!--[if IE 6]><link href="css/screen/ie/ie-6.css" rel="stylesheet" type="text/css" media="screen" /><![endif]-->
]
</head>
<body id="Body" runat="server">
<div id="main">
<div id="main-inner">
<div id="content" style="width:<%=DivWidth%>px;"><div id="content-top"></div><div class="content-inner"><asp:ContentPlaceHolder ID="contentPlaceHolder" runat="server" /><asp:ContentPlaceHolder ID="BelowLeftRightMainContent" runat="server" /></div> </div>
</body>
</html>
Second Master Page:
<%# Master Language="C#" MasterPageFile="~/global.master" AutoEventWireup="false" CodeFile="shopFalcon.master.cs" Inherits="shopFalcon" %>
<%# Register TagPrefix="FALCON" TagName="FeatureProducts" Src="~/FalconShopRightHand.ascx" %>
<%# Register TagPrefix="FALCON" TagName="ProductSearch" Src="~/FalconProductSearch.ascx" %>
<%# Register TagPrefix="FALCON" TagName="AbuseText" Src="~/FalconAbuseLinkDisplay.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="headPlaceholder" Runat="Server">
</asp:Content>
nothing in the code behind cept empty code behind
My content page:
<%# Page Language="C#" MasterPageFile="~/shop.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="shopFalcon_Default" Title="Shop Homepage" %>
<%# MasterType VirtualPath="~/shop.master"%>
<asp:Content ID="Content7" ContentPlaceHolderID="leftColPlaceHolder" Runat="Server">
<asp:Image ID="Image1" runat="server" ImageAlign="Right" ImageUrl="~/images/Free+Shipping+01.jpg" CssClass="img"/>
<h1>Shop Anytime, anywhere. </h1>
<div id="shopByBrandDiv">
</asp:Content>
My code behind:
protected void Page_Load(object sender, EventArgs e)
{
this.Master.Master.DivWidth = 955;
}
Again this works in Visual Studio using the built in web server but delpoying to the production server running IIS6 I get that error stated above.
Any ideas?
public int DivWidth { get; set; }
Does this actually get implemented?
Ok, here is the thing, this works sometimes and then when I add another property or recompile it would give me an error. it turns out it is compiler issue. To get around the issue, I had to create a App_Code directory under the root and made a class. When I get the error telling me there is no DivWidth defined, I simple make a code change in the class I created and the site compiles in the proper order. It took opening a case with MS, who was not very helpful, for me to find this workaround. Hope this helps someone else who runs into this strange issue.
this worked for me:
<%# MasterType VirtualPath="~/MasterPage.master" %>
in .aspx file