两个文件:test.aspx,testcls.cs,在testcls.cs文件中定义了一个类myclass(namespace是test),然后在test.aspx中调用
<%@ Page language="c#" Codebehind="testcls.cs" AutoEventWireup="false" Inherits="testcls" %>
但是在定义类变量时(testcls tcls=new testcls();)却提示错误了。
因为初学ASP.NET,所以不是很明白。
两个文件:test.aspx,testcls.cs,在testcls.cs文件中定义了一个类myclass(namespace是test),然后在test.aspx中调用
<%@ Page language="c#" Codebehind="testcls.cs" AutoEventWireup="false" Inherits="testcls" %>
但是在定义类变量时(testcls tcls=new testcls();)却提示错误了。
因为初学ASP.NET,所以不是很明白。
我将test.aspx中的引用改成<%@ Page Language="C#" AutoEventWireup="false" CodeFile="testcls.cs" Inherits="myClass" %>却提示如下错误,这是什么原因啊?
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).
Source Error:
Line 1: // testcls.cs
Line 2:
Line 3: using System;
Source File: f:\testcls.cs Line: 1
你是在哪里引用cs文件啊?
<%@ Page Language="C#" AutoEventWireup="false" CodeFile="testcls.cs" Inherits="myClass" %>这是代码分离的语句,不是引用cs的语句。
引用的话,要在.cs文件里引用。
我的例子里类和页面在两个文件夹中
兄弟,你这个用的vs的环境吧,我用的是微软的ASP.NET WEB Matrix Project调试环境,这小冬冬不能建立工程,所以不能像你说的那样using 工程.类文件夹来引用,我现在有index.aspx,index.aspx.cs,testcls.cs三个文件,想在testcls.cs里定义一个多个aspx文件都能调用的类,我现在index.aspx.cs里用using TEST;(TEST是Namespace)引用就出错,这样的话该如何引用?
只要是代码分离,都可以用using来引用啊。
如果不是代码分离的话,就用<%@ Import Namespace="System.IO"%>来引用