mikebai.com

  • Home
  • dev
  • DotNET
  • M365
  • 搞笑
  • 杂七杂八
  • FocusDict
個人BLOG
it developer
  1. Main page
  2. DotNET
  3. Main content

CodeFile、Src、Codebehind

2009-10-15 106hotness 0likes 0comments





<%@ Page Language="C#" AutoEventWireup="true" CodeFile="default.aspx.cs" Inherits="_Default" %>
<%@ Page Language="C#" AutoEventWireup="true" Src="default.aspx.cs" Inherits="_Default" %>
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="default.aspx.cs" Inherits="_Default" %>
以上三句,具体差别在哪?
---------------------------------------------------------------

src表示该aspx的源文件
codefile表示将运行时编译,比如VS2005中新建一个网站你会发现编译比WEB应用程序慢很多,但是可以修改代码后不用整体编译刷新页面就可以看到效果
codebehind就象.netfw1.1一样编译完后所有cs中的代码打包进dll
---------------------------------------------------------------
CodeBehind: 指定包含与页关联的类的已编译文件的名称。该属性不能在运行时使用。
提供此属性是为了与以前版本的 ASP.NET 的兼容,以实现代码隐藏功能。在 ASP.NET 2.0 版中,应改用 CodeFile 属性指定该源文件的名称,同时使用 Inherits 属性指定该类的完全限定名称。

  CodeFile

  指定指向页引用的代码隐藏文件的路径。此属性与 Inherits 属性一起使用可以将代码隐藏源文件与网页相关联。此属性仅对编译的页有效。

---------------------------------------------------------------

src 好象是 ASP.NET 1.x 才会有,2.0 的 code-behind 变成 CodeFile 了 .
Code-Behind 的好处就是它可以被编译,会比直接写在网页上的直译程序快,而且可以防止程序代码外泄的问题

 

 



移动项目开发笔记(用户控件引起对asp.net 2.0编译的思考)


来源:http://www.ittang.com/2008/0627/7216.html

 


一、起因:    
     开发团队的一名开发人员突然离职,他把他负责的模块任务交给了我。其中一个模块是他写了一个用户控件,我在我的页面尚始终都用不起,运行时发生错误,错误消息是:The base class includes the field *****, but its type (****) is not compatible with the type of control (ASP.webusercontrol_ascx).
 
二、经过:
    遇到这个问题后个人感觉那个用户控件在页面上注册没有成功。查找了页面注册代码:


<%@ Register Src="ProjectInfo.ascx" TagName="ProjectInfo" TagPrefix="uc3" %>
<uc3:ProjectInfo ID="ProjectInfo1" runat="server"&n

Tag: Nothing
Last updated:2009-10-15

mikebai

This person is a lazy dog and has left nothing

Like
< Last article
Next article >

COPYRIGHT © 2025 mikebai.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang