Thursday, August 18, 2016

*.aspx, *.aspx.cs, *.aspx.designer.cs. / AutoEventWireup / Code file / Behind

.aspx is markup file. Contains things such as HTML, CSS, JavaScript, and ASP markup.(run on client side)

.aspx.cs is codebehind file. (run on server side)

.aspx.designer.cs 
is files are the bridge for code-behind files and the .aspx markup files
  • Any server control existing on the .aspx markup page is represented here.
  • Most important are the name and type of the server control
  • allows Visual Studio to give the user IntelliSense in the code-behind page for server controls created at design-time.
_________________________________________________________________________

.aspx page have 2 models (same function, same perfomance):
  •  Single-File page model
  • Code-behind page model
Code Behind Page Model
  • keep the markup in 1 file, programming code in another file (*.cs)
  • Clean separation of the markup (user interface) and code. 
  • It is allow designer working on the markup while a programmer writes code.
Single File Page Model Consist below in aspx :
  • You can see the code and the markup in one place.
  • Easy deploy and send to another programmer, because only 1 File.

<script runat="server">
void Button1_Click(Object sender, EventArgs e) 
    Label1.Text = "Clicked at " + DateTime.Now.ToString(); 
}</script>



_________________________________________________________________________


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Q14Cookies.Default" %>

AutoEventWireup 

  • True : Page Event has initialized automatically. 
  • False : Page Event initialize manually.

override protected void OnInit(EventArgs e)
{
    this.Load += new System.EventHandler(this.Page_Load);
}

Inherits
  • Carry the class name which inside the code behind file.
  • You can have mutiple classes in same code behind file and inherit in 2 different .aspx file.
CodeBehind
  • Need to compile in Visual Studio before deploy.
  • The compiled binary is placed in the bin folder.
  • Source code is not view able as plain text. (good to deliver to customer)
  • For Web Application.
CodeBehind
  • Need the .cs physical file at deployment folder.
  • Source code (.cs) is view able as plain text.
  • For Web sites project.

No comments:

Post a Comment