Page Directive Error After Copying Default.aspx From Another Project?
In my web-application (asp.net, C#) in solution explore I copy and paste the default.aspx page which is in the other project. When I run the default.aspx page it is giving error like this
<%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false" Inherits="Default" %>
Parser Error Message: Could not load type 'Default'开发者_StackOverflow.
Can anyone tell me how to fix this?
In addition to making sure that the class names match, as stated in an earlier answer, there are important differences between the "Codebehind" and "CodeFile" directives. The former, which you're using, is the older, .NET 1.1 way of doing things. In that case, in your code behind you have to declare instances of all of the controls on your page that you need to access, and you shouldn't use partial classes.
For CodeFile, you must use partial classes, and you don't need to declare any of the controls; that work is done for you in the other part of the partial class.
If you're porting an existing page, you need to understand which model it needs, and use the corresponding declarations in both the code behind and the Page directive.
What is the class in your .aspx.cs file? Should be something similar to:
public partial class Default : System.Web.UI.Page
Sometimes it's created as _default
精彩评论