Friday 4 November 2011

What?s the difference between Codebehind="MyCode.aspx.cs" andSrc="MyCode.aspx.cs"?


CodeBehind is relevant to Visual Studio.NET only

         Code All build Assembly is placed inside the bin folder
Src the source cs file/vb fiel is placed in the source
folder and the source file is complied and assembly is
placed inside bin folder during runtime of the aspx page.

         
code behind is created through assembly that's defined in bin
folder and src is definded in outward of bin folder that is not
making dll and .exe file.

          

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

Whereas 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 attribute means you deploy the source code files and everything is compiled JIT (just-in-time) as needed. Many people prefer this since they don't have to manually worry about compiling and messing with dlls -- it just works. Of course, the source is now on the server, for anyone with access to the server -- but not just anyone on the web.

CodeBehind attribute doesn't really "do" anything, its just a helper for VS.NET to associate the code file with the aspx file. This is necessary since VS.NET automates the pre-compiling that is harder by hand, and therefore the Src attribute is also gone. Now there is only a dll to deploy, no source, so it is certainly better protected, although its always decompilable even then.