Inherit problem in asp.net

前端 未结 4 1711
野性不改
野性不改 2020-12-19 09:26

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 thi

相关标签:
4条回答
  • 2020-12-19 09:46

    In aspx page, there will be

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    

    And in .cs page

    public partial class _Default : System.Web.UI.Page{}
    

    Inherits attribute and the class name both should be same. Hope this resolves the issue.

    0 讨论(0)
  • 2020-12-19 09:50

    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.

    0 讨论(0)
  • 2020-12-19 09:56

    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.

    0 讨论(0)
  • 2020-12-19 10:00

    In your aspx page there will be the following at the top:

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

    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.

    You probably copied the whole contents of one of the files and now the two pieces no longer match up.

    0 讨论(0)
提交回复
热议问题