9

Can any one tell me with example what's the difference between Codebehind="MyCode.aspx.cs" and Src="MyCode.aspx.cs"?

Monika
  • 2,172
  • 15
  • 24

2 Answers2

7

CodeBehind

Specifies the name of the compiled file that contains the class associated with the page. This attribute is not used at run time. This attribute is used for Web application projects. The CodeFile attribute is used for Web site projects.

Needs to be compiled ( asp.net 1.1 model) and compiled binary is placed in the bin folder of the website. You need to do a compile in visual studio before you deploy. Good model when you do not want the source code to be viewable as plain text ... for example when delivering to a customer who you not have obligation to provide code.

Src

Specifies a path to a source file containing code that is linked to the page. In the linked source file, you can choose to include programming logic for your page either in a class or in code declaration blocks.

You can use the Src attribute to link build providers to the page. For more information, see the BuildProvider class. Also, in versions of ASP.NET prior to 2.0, the Src attribute was used as an alternative way to link a code-behind file to a page. In ASP.NET 2.0, the preferred approach to linking a code-behind source file to a page is to use the Inherits attribute to specify a class, along with the CodeFile attribute to specify the path to the source file for the class.

You provide the source file with the solution for deployment. ASP.NET 2.0 runtime compiles the code when needed. The compiled files are at Microsoft.NET[.NET version]\Temporary ASP.NET Files.

Its always recommended to check the official documentations first. See the msdn documentation for this Question.

Subin Jacob
  • 4,692
  • 10
  • 37
  • 69
  • 1
    In short terms, CodeBehind gets built into an assembly, whereas the file referenced in the CodeFile/src needs to be deployed with the ASPX on the web server. With CodeBehind approach you'll need to deploy a new assembly for each change to the backend logic, whereas the CodeFile approach you can edit backend code from the server (directly in the .cs file) – scheien Dec 12 '13 at 12:34
1

codebehind is a particular particular technique born with NET. This allows you to write application code by separating it from the graphical presentation.

For example:

<script runat="server" src="MyCods.cs" />

execute a primitive code-behind. this because the code isnot compiled and not generate. For This reason remain a simple format plain text.

Il codebehind is default applied in the major IDE as: Microsoft Visual Studio 2003 - .net 1 Microsoft Web Matrix - .net 1 Microsoft Visual Studio 2005 .net 2 Microsoft Web Developer Express .net 2

This implies that the association of the source code, in the form of DLLs, the page to which it is related. I remind you that each page is viewed. NET as a single class, which will inherit the code derived from. Previously compiled dll.

Francesco Irrera
  • 445
  • 4
  • 21