ASP.NET 4.0 Visual Studio Express - Parse error - asp.net

I am getting this after
compiling,
made sure bin directory has the compiled DLL files.
What am I missing?
Server Error in '/' Application.
Parser Error
Description: An error occurred during the parsing of a resource
required to service this request. Please review the following specific
parse error details and modify your source file appropriately.
Parser Error Message: Could not load type 'WebApplication1.WebForm1'.
Source Error:
Line 1: <%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
Line 2: <!DOCTYPE html>
Line 3: Source File: /test/WebForm1.aspx Line: 1

check your namespace that is assigned to WebForm1. When I encounter this error it's typically due to me changing the namespace and not updating the line in .aspx file.
It may look like
namespace MyRenamedNamespace
{
public class WebForm1
{
}
}
in which case the line in the .aspx file should read
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="MyRenamedNamespace.WebForm1" %>

That means that the it cannot find the type/class of WebApplication1.WebForm1. I'd look in your code behind or WebForm1.aspx.cs and see if it looks something like:
namespace WebApplication1 {
public class WebForm1 {
protected void Page_Load(object sender, EventArgs e) {
}
}
}
I'd imagine your missing a namespace, or class name. If you can't find the code behind, I'd be tempted to recreate the page and Visual Studio should crate it for you.

Related

ASP.Net Calling Site.Master method from web page not working

I saw on several web pages how to interface to a public method defined in a master file from a web page call behind code that uses that master file.
(I am using ASP.Net 4.0 on Visual Studio 2012.)
The procedure is (copied from article):
Make sure the function is accessible to the page (i.e. declared
public), and use the MasterType declaration in the ContentPage:
<%# Page .... %>
<%# MasterType VirtualPath="~/masterpage.master" %>
In the page, use Page.Master.MyFunction() to access the function.
*Note: before being able to access the function, you'll need to save & build.
The problem is that I do not see the method. Here is what I have:
Web Page (stored in /MyFolder, so /MyFolder):
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Logout.aspx.cs" Inherits="BvCorpMain.Candidates.Logout" %>
<%# MasterType VirtualPath="/SiteMasters/Site.Master" %>
Site.Master CS file (stored in /SiteMasters folder):
public void UpdateUserBlocksToCookie()
{
}
When I go into the code behind for the logout page and in a method I type in "Page.Master.", I do not see my method.
Your page is inheriting from System.Web.UI.Page, which only knows that its master page is of type System.Web.UI.MasterPage. If you are making modifications to a child class of MasterPage, then you need to cast the Page.Master property to your child class.
public class MyPage : System.Web.UI.Page
{
public new MyMaster Master { get { return base.Master as MyMaster; } }
public void Page_Load(object sender, EventArgs e)
{
Master.MyMasterPageFunction();
}
}
public class MyMaster : System.Web.UI.MasterPage
{
public void MyMasterPageFunction()
{
}
}
The previous answer did educate me, however I believe the resolution was to restart VS2012, maybe cleaning the solution and rebuilding did not hurt. Either way.
Microsoft adds in the following code automatically to the .aspx.designer.cs file.
/// <summary>
/// Master property.
/// </summary>
/// <remarks>
/// Auto-generated property.
/// </remarks>
public new MyNamespace.Site Master {
get {
return ((BvCorpMain.Site)(base.Master));
}
The previous answer conflicts with this definition. Also, the previous answer of MyMaster, although granting access does not give (automatically at least) to needed form information. I checked. Using the existing master file is the cleanest.
The definition for the master.cs file is:
namespace MyNamespace
{
public partial class Site : System.Web.UI.MasterPage
As you can see, Microsoft did give access to MyNamespace.Site, which is what I needed, with "Master.".
I did not think to check the .aspx.designer.cs file for that definition, when I was having the problems. Possibly the definition was lacking and got added later, when either I rebuilt or did a save, which I had previously done, or whatever.
Knowing the addition does simplify things, as I can add that in manually if it does not exist using that construct.

ASP.NET Page does't show code behind code when clicking on Design code

Page does't show code behind code when clicking on Design code and also code behind code display error as control not found
Below code display error : System Error
<%#Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="Register" %>
I don't why it fetches this type of error ,please help me
Code Behind:
using System;
The only reason for which the designer cannot open the code behind is because it cannot find the associated code behind file specified Inherits="Register"
Make sure you have a public class named Register that must be Partial as well
make sure also the the code behind file name is named as Register.aspx.cs
must check make Inherits attributed in design and code file path
Ok, I totally misunderstood your question.
If your Register.aspx file looks like this:
<%#Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="Register" %>
The Register.aspx.cs should look (at least) like this:
using System;
namespace YourDefaultNamespace
{
public partial class Register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
I notice that you don't have a namespace in the Inherits attribute of your <%# Page %> directive. It should have the same namespace as your codebehind file. In my example that's YourDefaultNamespace, so my <%# Page %> directive should be this:
<%#Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="YourDefaultNamespace.Register" %>

Failed to Parse Manifest : Using asp.net

I am following Stephen Walther's guide and everything builds without errors. However once I run the application in Chrome I get this error message:
Application Cache Error event: Failed to parse manifest http://localhost/website/Manifest.ashx
And nothing is cached.
From what I have gathered from here, I have a type-o in my manifest. Maybe you can see something I did wrong and causing this error message.
Manifest.ashx:
<%# WebHandler Language="C#" Class="JavaScriptReference.Manifest" %>
using System;
using System.Web;
namespace JavaScriptReference {
public class Manifest : IHttpHandler {
public void ProcessRequest(HttpContext context) {
context.Response.ContentType = "text/cache-manifest";
context.Response.WriteFile(context.Server.MapPath("Manifest.txt"));
}
public bool IsReusable {
get {
return false;
}
}
}
}
Manifest.txt:
CACHE MANIFEST
CACHE:
Images/img1.jpg
Images/img2.jpg
JScript.js
Default.aspx.vb
# Does Default.aspx.vb even need to be cached?
TLDR: Don't add a CACHE: entry in your manifest, don't cache code-behind files and make sure you registered the HttpHandler in your Web.Config
Long Version:
There are a few things that you need to do to make the sample app work. First up you create your handler as above, an example in C# is:
using System.Web;
namespace CacheTest
{
public class Manifest : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/cache-manifest";
context.Response.WriteFile(context.Server.MapPath("Manifest.txt"));
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
Next you need to register the handler in your web.config like:
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="Manifest.ashx"
type="CacheTest.Manifest, CacheTest" />
</httpHandlers>
</system.web>
</configuration>
Next up create a Manifest.txt in the root of your website and populate it. The sample should not have a CACHE: heading inside it. A working sample may look like:
CACHE MANIFEST
# v30
Default.aspx
Images/leaping-gorilla-logo.png
Note that we do not cache code behind files, only relative paths to actual resources that a browser may request. Finally, add a Default.aspx file. Ignore the code behind but edit the markup so that the initial HTML tag references the HttpHandler, the full markup:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CacheTest.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" manifest="Manifest.ashx">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
This is a sample offline app!
</div>
</form>
</body>
</html>
With this done you can now start your website, browse to it in FireFox and you will be asked permission to take it offline. Alternatively, fire it up in Chrome, switch to the developer tools, check the Resources tab and you will be able to see the resources that have been loaded under the Application Cache node:
And for completeness, your finished code structure will look like:
The error "Application Cache Error event: Failed to parse manifest" can be caused by formatting of the text file.
My deployment script generated the manifest file in Unicode. The file looked fine in Chrome (when going to the URL), validated on online validators, but would generate this error when being used as a manifest.
To fix the file, just open the manifest file in notepad and go to "Save-As" and select UTF8.

page is not allowed here because it does not extend class 'System.Web.UI.MasterPage'

I am creating a website using master page, which works fine. but after I add entity data model and some retrieval code into the login page, it comes some errors
the code is like
var tombstoneQuery = from t in crnnsupContext.Tombstones.Include("ProvState")
where t.RegNumber == _username
select t;
List<Tombstone> tombstoneResult = tombstoneQuery.ToList();
Cache.Insert("Tombstone", tombstoneResult);
the first error is happened when i try to put the list into the Cache, the error says "Thread was being aborted. After I set cache.insert statement as a commend, this error was gone, but the next one came
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: 'OnlineRenewal.Renewal' is not allowed here because it does not extend class 'System.Web.UI.MasterPage'.
Source Error:
Line 1: <%# Master Language="C#" AutoEventWireup="true" CodeBehind="renewal.Master.cs" Inherits="OnlineRenewal.Renewal" %>
Line 2:
Line 3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
the Renewal is the master page which i didn't do anything with it.
anyone can help? thanks a lot
the code for renewal page. (there is noting there)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace OnlineRenewal
{
public partial class renewal : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="renewal.Master.cs" Inherits="OnlineRenewal.Renewal" %>
This is telling you that OnlineRenewal.Renewal is not a master page.
Ensure it has a <%# Master %> directive at the top of the page, or change the inherits attribute of the page that is causing this error to something else.

Type '_Default' already defines a member called 'Page_Load' with the same parameter types

I've been renaming some classes and packages in my aspx project and now i have this error:
"Type '_Default' already defines a member called 'Page_Load' with the
same parameter types"
I have two aspx pages. In the default.aspx codebehind i see:
Default.aspx:
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="_Default" %>
Default.aspx.cs:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
//error line under 'Page_Load'
}
search.aspx:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="search.aspx.cs" Inherits="_Default" %>
search.aspx.cs:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
}
Every new ASPX page I add to my project is automaticly added to some namespace.
I've tried changing the inherits attribuut. But i couldn't find a way to fix this error and to get rid of the namespace.
I'm using Visual Studio 2010.
Every page you add is automatically configured to namespace depending on your folder structure. I don't see enough code and structure, but are you sure, that you don't have the Page_Load defined twice? At least the error message says so. Does it behave same even when you use different class name than _Default ?
After edits:
Yea, there we go. You define same class (_Default) in both Default.aspx and Search.aspx ... You should rename your classes according to conventions. ie: use class "Default" in your Default.aspx and use class "Search" in your Search.aspx
Double click the error, temporarily rename the Page_Load to something else. Go down into the body of the function and type Page_Load. Press F12. That will get you to the place where you have second Page_Load method already defined. You'll probably see that it's in another partial _Default class in the same namespace.
Just to add up a specific case.
You can come across to this situation when you convert Web Site into Web Application.
When your project in form of Web Site, when you add for example Default.aspx into two different folders they both created without namespace with the same class name. Both declared partial and it is just fine. But when you convert into Web Application and try to build they start conflicting as they are in the same namespace, declared partial and have their own Page_Load methods.
One of the solutions can be giving distinct class names or encapsulating into different namespaces in accordance with the folder structure.
Since your class is public partial class _Default it's probably some naming that is causing the problem. Try to identify the other part(s) of _Default. Since it's a partial class you're able to have as many partials as you want.. Problem is probably that Page_Load is defined in one of those.
Below follows issues I have encountered when copying files into my solution, clicking on the reported error or on "Go to Definition" mislead me to spot the cause. The hint is one line above..... !
I'm exposing the Problem AND how I finally Resolved it.
Errors when building the application:
Error 1 Type 'Solution1.Web.yourABC' already defines a member
called 'Page_Load' with the same parameter types
C:\\trunk\Solution1.Web\yourABC.aspx.cs 12 24
Solution1.Web
Error 2 Type 'Solution1.Web.yourABC' already defines a member
called 'Page_Load' with the same parameter types
C:\\trunk\Solution1.Web\GuideABT.aspx.cs 12 24
Solution1.Web
How the problem arose:
I copy/pasted a file .aspx in the same solution to make a new file.
C#: Error like below started to appear; worst other misleading errors started to impact the application at runtime:
* Be aware that error 1 IS NOT an error it is CORRECT, as it is the source code
Error 1 Type 'Solution1.Web.yourABC' already defines a member called 'Page_Load' with the same parameter types C:\<folderpath>\trunk\Solution1.Web\yourABC.aspx.cs 12 24 Solution1.Web
Error 2 Type 'Solution1.Web.yourABC' already defines a member called 'Page_Load' with the same parameter types C:\<folderpath>\trunk\Solution1.Web\GuideABT.aspx.cs 12 24 Solution1.Web
Both classes "Page_Load" are empty, normally they are generated automatically by the Visual Studio Engine
Solution:
Change the .cs file of the newly create/pasted aspx page to reflect the page name after the Class "name". In this case "GuideABT.aspx" is the new pasted & renamed aspx file:
Correction on Error 1: NO CORRECTION NEEDED as it is the copied from file. MAKE SURE THAT the name of the file and the name of the class reference ARE the same in the .cs files:
File name yourABC.aspx, check the .cs extension files:
namespace Solution1.Web
{
public partial class yourABC : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
Correction on Error 2: MODIFY the pasted file. Correct the CLASS NAME to reflect the name of the .aspx file.
File name GuideABT.aspx, check the .cs extension files:
ORIGINAL code in .cs
namespace Solution1.Web
{
public partial class *yourABC* : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
CORRECTED this code in .cs TO
namespace Solution1.Web
{
public partial class **GuideABT** : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
Issue RESOLVED.
Cheers.

Resources