Professional Documents
Culture Documents
ASPINTRTODUCTION
ASPINTRTODUCTION
ASP.NET
ASP.NET is a part of Microsoft .NET Framework. The following image shows the
component stack.
Asp.net features
o Support for Cross-Platform and Container Environments
o Asynchronous with the use of Async/Await
o Server Controls
o Master Pages
o Comprehensive Development Environments
o Working with data
o Membership
o Client Script and Client Frameworks
o Routing
o State Management
o Security
o Asp.net engine and razor engine
o Performance
o Error Handling
o Testable
o Easy deployment
o Cost effective
Asp.net architecture
Document language:html5
Webserver :IIS,WAS
Network :internet,intranet,extranet
Protocol: :http
Asp.net engine
Asp.net engine
In ASP.NET, a web page has execution lifecycle that includes various phases. These
phases include initialization, instantiation, restoring and maintaining state etc. it is
required to understand the page lifecycle so that we can put custom code at any
stage to perform our business logic
Page Lifecycle stages
A requested page first loaded into the server memory after that processes and sent
to the bowser. At last it is unloaded from the server memory. ASP.NET provides
methods and events at each stage of the page lifecycle that we can use in our
application. In the following table, we are tabled events.
Load
Render
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script runat="server">
void init(object sender,EventArgs arg)
{
Response.Write("<h1>initialisation completed....<hr>");
}
</script>
</head>
<body>
<form id="form1" runat="server" oninit="init">
<div>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm7.aspx.cs"
Inherits="dynamic_doc.WebForm7" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script runat="server">
void init(object sender,EventArgs arg)
{
Response.Write("<h1>initialisation completed....<hr>");
}
void load(object sender,EventArgs arg)
{
Response.Write("<h1>load completed....<hr>");
}
</script>
</head>
<body>
<form id="form1" runat="server" oninit="init" onload="load">
<div>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm7.aspx.cs"
Inherits="dynamic_doc.WebForm7" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script runat="server">
void init(object sender,EventArgs arg)
{
Response.Write("<h1>initialisation completed....<hr>");
}
void load(object sender,EventArgs arg)
{
Response.Write("<h1>load completed....<hr>");
}
void render(object sender,EventArgs arg)
{
Response.Write("<h1>render completed....<hr>");
}
</script>
</head>
<body>
<form id="form1" runat="server" oninit="init" onload="load" onprerender="render">
<div>
</div>
</form>
</body>
</html>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script runat="server">
void init(object sender,EventArgs arg)
{
Response.Write("<h1>initialisation completed....<hr>");
}
void load(object sender,EventArgs arg)
{
Response.Write("<h1>load completed....<hr>");
}
void render(object sender,EventArgs arg)
{
Response.Write("<h1>render completed....<hr>");
}
</script>
</head>
<body>
<form id="form1" runat="server" oninit="init" onload="load" onprerender="render">
<div>
</div>
</form>
</body>
</html>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script runat="server">
void init(object sender,EventArgs arg)
{
Response.Write("<h1>initialisation completed....<hr>");
}
void load(object sender,EventArgs arg)
{
Response.Write("<h1>load completed....<hr>");
}
void render(object sender,EventArgs arg)
{
Response.Write("<h1>render completed....<hr>");
}
</script>
</head>
<body>
<form id="form1" runat="server" onload="load" onprerender="render" oninit="init">
<div>
</div>
</form>
</body>
</html>
}
protected void Page_Init(object sender, EventArgs e) {
//If the page is post back, then label contrl values will be loaded from view state.
//E.g: If you string str = Label1.Text, then str will contain viewstate values.
//But "SaveStateComplete" values will not be available during post back. i.e.
View state.
//Work and it will not effect label contrl, view stae and post back data.
Asp.net compilation
Server Controls
The following table contains the server-side controls for the Web Forms.
Code behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace dynamic_doc
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("<h1>page load.....");
}
}
}
Inline
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="dynamic_doc.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("<h1>page load.....");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Inline
Code behind
C# in asp.net
1)inline
Script runat=server
2)code behind
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<% string str = "asp.net engineee";Response.Write(str); %>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs"
Inherits="dynamic_doc.WebForm3" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<%
string str = "you,rama,raja,rani";
int x;
string[] arr = str.Split(',');
for(x=0;x<=arr.Length-1;x++)
{
if(x%2==0)
{
Response.Write("<h1>" + arr[x]);
}
else
{
Response.Write("<h2>" + arr[x]);
}
}
%>
</div>
</form>
</body>
</html>