-----------------------------------------------------------
New Message on MumbaiUserGroup
-----------------------------------------------------------
From: Swapnil_B1
Message 1 in Discussion
The ASP.NET 2.0 Coding Model
In ASP.NET 1.x, you could develop an ASP.NET page in one of two ways. First,
you could put your code directly inline with your ASP.NET tags. The code inline
model is very similar to the coding model that was prevalent with classical ASP
and other scripting languages. However, the code inline model has several
problems such as the intermixing of code and HTML. ASP.NET 1.0 introduced the
code behind model as a replacement. The code behind model used an external
class to house the code, while the ASPX page contained the HTML and ASP.NET
tags. The code behind model thus successfully separated code from content;
however it created some interesting inheritance issues and forced the developer
to keep track of two files for each Web page. Code Behind
As in ASP.NET 1.x, the default code model is the code behind model. If you want
to work with a separate code file, you have to create the file when you create
the ASPX page. Fortunately, creating a code behind file is as simple as
clicking a checkbox when you decide to create a new page.
The primary difference between a code behind file in ASP.NET 1.x and ASP.NET
2.0 is that a code behind file is now a partial class rather than a full class
that inherits from the ASPX page. A partial class is a new .NET construct that
allows you to define a single class in multiple source files. In ASP.NET 2.0, a
partial class is particularly useful for code behind files as it removes the
inheritance relationship that is present with the older code behind model.
An old code behind file (c#)
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
private void Page_Load(object sender, System.EventArgs e)
{ }
#region Web Form Designer generated code override protected void
OnInit(EventArgs e) { InitializeComponent(); base.OnInit(e); }
private void InitializeComponent()
{ this.Load += new System.EventHandler(this.Page_Load); }
#endregion
void Page_Load(object sender, EventArgs e)
{ Label1.Text = "Hello ASP.NET 2.0"; }
}
A new code behind file
namespace ASP
{
public partial class Webform1_aspx : System.Web.UI.Page
{
void Page_Load(object sender, EventArgs e)
{ Label1.Text = "Hello ASP.NET 2.0"; }
}
}
As you can see, the new code behind file is much cleaner and easier to read.
The code behind file has automatic access to any controls added to the ASP.NET
page, and Visual Studio 2005 will provide automatic IntelliSense support and
synchronization. Visual Studio also recognized when you are using a code behind
file and opens the file rather than the source view when you double click on a
control to access its events.
Swapnil (Swaps)
http://swapsnet.spaces.live.com/
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/MumbaiUserGroup/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you
received this message by mistake, please click the "Remove" link below. On the
pre-addressed e-mail message that opens, simply click "Send". Your e-mail
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]