我在用Codebehind时出现这样的错误.
分析器错误信息: 未能加载类型“tr.WebForm1”。源错误: 
行 1:  <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="tr.WebForm1" %>
行 2:  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
行 3:  <HTML>
 
我把Codebehind改为Src就可以了.用Codebehind不可以的吗.该怎样设置.

解决方案 »

  1.   

    编译以后就没有这个错误了!CodeBehind :
    Specifies the name of the compiled file that contains the class associated with the page. This attribute is used by the Visual Studio .NET Web Forms designer. It tells the designer where to find the page class so that the designer can create an instance of it for you to work with at design time. For example, if you create a Web Forms page in Visual Studio called WebForm1, the designer will assign the Codebehind attribute the value of WebForm1.aspx.vb, for Visual Basic, or WebForm1.aspx.cs, for C#. This attribute is not used at run time. Src:
    Specifies the source file name of the code-behind class to dynamically compile when the page is requested. You can choose to include programming logic for your page either in a code-behind class or in a code declaration block in the .aspx file.
      

  2.   

    你检查一下,你程序在IIS中是否是虚拟目录,如果不是,你应该把程序目录下BIN下的DLL文件放到IIS根目录下.比如你的IIS设置的是C:\Inetpub\wwwroot目录,你就要在这上面建一个BIN目录,然后把你程序目录下BIN下的DLL复制过去,如果你的本身就是虚拟目录,那就不用了.
      

  3.   

    Codebehind="WebForm1.aspx.cs" 是在编译的时候调用WebForm1.aspx.cs文件生成相关的dll
    以后请求页面的时候直接从dll中读取后台操作指令(这里要用到Inherits="tr.WebForm1"),你没有编译生成dll,所以在使用codebehind的时候出错Src="WebForm1.aspx.cs"是在每次请求页面的时候调用WebForm1.aspx.cs进行动态编译,根本用不到Inherits="tr.WebForm1",所以不会出错了。两者比较起来,使用Codebehind更好一些,一是执行效率高(Src每次请求都编译),二是可以保护你的劳动成果(使用Src你得把*.cs文件一起发布)这是我的个人理解啊~~ 嘿嘿