Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between "codebehind" and "source"

Tags:

c#

asp.net

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

like image 535
Monika Avatar asked Dec 12 '13 11:12

Monika


1 Answers

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.

like image 50
Subin Jacob Avatar answered Oct 04 '22 10:10

Subin Jacob