wt lab5

5
LAB EXERCISE - 5 Q1: -WAP to implement the difference between HTML and ASP.Net controls <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> Difference between HTML and ASP.Net Controls<br /> <asp:Label ID="Label1" runat="server" Text="ASP TextBox"></asp:Label> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <asp:Label ID="Label2" runat="server" Text="HTMLTextBox"> </asp:Label> <input id="Text1" type="text" /><br /> <asp:Button ID="Button1" runat="server" Text="click" /> </div> </form> <p> &nbsp;</p> </body> </html>

Upload: kuku288

Post on 11-Dec-2015

212 views

Category:

Documents


0 download

DESCRIPTION

lab5

TRANSCRIPT

Page 1: wt lab5

LAB EXERCISE - 5

Q1: -WAP to implement the difference between HTML and ASP.Net controls

<%@ Page Language="C#" AutoEventWireup="true"

CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div> Difference between HTML and ASP.Net Controls<br />

<asp:Label ID="Label1" runat="server" Text="ASP TextBox"></asp:Label>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<br />

<asp:Label ID="Label2" runat="server" Text="HTMLTextBox">

</asp:Label> <input id="Text1" type="text" /><br />

<asp:Button ID="Button1" runat="server" Text="click" />

</div>

</form>

<p> &nbsp;</p>

</body>

</html>

Page 2: wt lab5

Q2:- Write a program to implement the difference between static variable and

viewstate variable

using System;

using System.*;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

namespace WebApplication1

{ public partial class WebForm2 : System.Web.UI.Page

{ static int i = 0;

protected void Page_Load(object sender, EventArgs e)

{ if(!IsPostBack)

TextBox1.Text = (i++).ToString(); }

protected void Button1_Click1(object sender, EventArgs e)

{ TextBox1.Text = (i++).ToString();

} } }

Q3:-Write a program to implement application and session state events in the

.NET page lifecycle.

Global.asax.cs

using System;

using System.*;

Page 3: wt lab5

using System.Web.Security;

using System.Web.SessionState;

using System.Xml.Linq;

namespace WebApplication2

{ public class Global : System.Web.HttpApplication

{ protected void Application_Start(object sender, EventArgs e)

{ Application["TotalApplications"] = 0;

Application["TotalUsers"] = 0;

Application["TotalApplications"] = (int)Application["TotalApplications"] + 1;

}

protected void Session_Start(object sender, EventArgs e)

{ Application["TotalUsers"] = (int)Application["TotalUsers"] + 1;

} } }

Webform1.aspx.cs

using System;

using System.*;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

namespace WebApplication2

{ public partial class WebForm1 : System.Web.UI.Page

{ protected void Page_Load(object sender, EventArgs e)

{ Response.Write("Number of

Application"+Application["TotalApplications"]);

Response.Write("<br/>");

Response.Write("Number of Users Online:" + Application["TotalUsers"]);

} } }

Page 4: wt lab5

Q4:-Write a program to implement the difference between View State and

session state variable.

Webform1.aspx.cs

using System;

using System.*;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

namespace WebApplication1

{ public partial class WebForm3 : System.Web.UI.Page

{ int clickcount = 0;

protected void Page_Load(object sender, EventArgs e)

{ if (!IsPostBack)

{ if (ViewState["clicks"] == null)

{ ViewState["clicks"] = 0; }

TextBox1.Text = ViewState["clicks"].ToString(); }

}

protected void Button1_Click(object sender, EventArgs e)

{ if (ViewState["clicks"] != null)

{ int clickcount = (int)ViewState["clicks"] + 1;

TextBox1.Text = clickcount.ToString();

ViewState["clicks"] = clickcount;

} } } }

Webform2.aspx.cs

using System;

using System.*;

using System.Web.Security;

Page 5: wt lab5

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

namespace WebApplication1

{ public partial class WebForm4 : System.Web.UI.Page

{ int clickcount = 0;

protected void Page_Load(object sender, EventArgs e)

{ if (!IsPostBack)

{ if (ViewState["clicks"] == null)

{ ViewState["clicks"] = 0; }

TextBox1.Text = ViewState["clicks"].ToString();

} }

protected void Button1_Click(object sender, EventArgs e)

{ if (ViewState["clicks"] != null)

{ int clickcount = (int)ViewState["clicks"] + 1;

TextBox1.Text = clickcount.ToString();

ViewState["clicks"] = clickcount;

} } } }

Webform1

Webform2