C# asp.net中的继承问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1671747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Inherit problem in asp.net
提问by Surya sasidhar
in my web application i copy and paste the code from other site to in my page also the source code starting form when i run the application it is giving the error like this
在我的网络应用程序中,我将其他站点的代码复制并粘贴到我的页面中
Server Error in '/DomainIV' Application.
“/DomainIV”应用程序中的服务器错误。
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: ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).
编译器错误消息:ASPNET:确保此代码文件中定义的类与“继承”属性匹配,并且它扩展了正确的基类(例如 Page 或 UserControl)。
Source Error:
源错误:
Line 1: using System; Line 2: using System.Data; Line 3: using System.Web;
第 1 行:使用系统;第 2 行:使用 System.Data;第 3 行:使用 System.Web;
Source File: c:\Inetpub\wwwroot\DomainIV\WhoIs.aspx.cs Line: 1
源文件:c:\Inetpub\wwwroot\DomainIV\WhoIs.aspx.cs 行:1
this is my problem help me thank u.
这是我的问题,帮我谢谢你。
采纳答案by Kelsey
In your aspx page there will be the following at the top:
在您的 aspx 页面中,顶部将显示以下内容:
<%@ Page Language="C#" MasterPageFile="~/Test.Master" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="TestApp.Test" Title="Untitled Page" %>
In your .cs file your class will be defined like:
在您的 .cs 文件中,您的类将被定义为:
namespace TestApp
{
public partial class Test : System.Web.UI.Page
{
Make sure the inherits property in the aspx page matches the class definition in the .cs file. In the example above it is 'TestApp.Test' in the inherits property and the class must have the same namespace and classname TestApp and Test.
确保 aspx 页面中的继承属性与 .cs 文件中的类定义匹配。在上面的示例中,继承属性中是“TestApp.Test”,并且该类必须具有相同的命名空间和类名 TestApp 和 Test。
You probably copied the whole contents of one of the files and now the two pieces no longer match up.
您可能复制了其中一个文件的全部内容,现在这两部分不再匹配。
回答by o.k.w
My advice, create the new page with the same file name as the source.
Then copy and paste the codes into the new pages (APSX and code-behind). Works for me everytime.
我的建议是,创建与源文件名相同的新页面。
然后将代码复制并粘贴到新页面(APSX 和代码隐藏)中。每次都对我有用。
回答by Michael Petito
In your ASPX file, make sure the @Page declaration has an Inherits attribute that matches the full class name of the class in your code behind file. This declaration is usually the first line of the ASPX file. Also make sure that the class in your code behind file inherits System.Web.UI.Page and that it is not a sealed class.
在 ASPX 文件中,确保 @Page 声明具有与代码隐藏文件中类的完整类名匹配的 Inherits 属性。此声明通常位于 ASPX 文件的第一行。还要确保您的代码隐藏文件中的类继承 System.Web.UI.Page 并且它不是密封类。
回答by adi
In aspx page, there will be
在aspx页面中,会有
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
And in .cs page
在 .cs 页面中
public partial class _Default : System.Web.UI.Page{}
Inherits attribute and the class name both should be same. Hope this resolves the issue.
Inherits 属性和类名都应该相同。希望这能解决问题。