0% found this document useful (0 votes)
7 views10 pages

AWT Module 4

Uploaded by

amitpatel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views10 pages

AWT Module 4

Uploaded by

amitpatel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Module 4: State Management and AJAX

Practical No. 29 <br />


<asp:Label ID="Label5" runat="server" Font-
Aim: Create a Web application Bold="True" Font-Size="Larger" Text="Query
demonstrating client-side state management String"></asp:Label>
<br />
using all the techniques. <br />
<asp:TextBox ID="TextBox2"
[Link]: runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<%@ Page Language="C#" AutoEventWireup="true"
<asp:Button ID="Button5" runat="server"
CodeBehind="[Link]"
OnClick="Button5_Click" Text="Send" Width="61px"
Inherits="[Link]
/>
onManagement" %>
<br />
<br />
<!DOCTYPE html>
<h2>Reading/Writing Cookies</h2><br/>
Cookie Name&nbsp; <asp:TextBox ID="NameField"
<html xmlns="[Link]
runat="server"></asp:TextBox><br/><br/>
<head runat="server">
<br/>
<title></title>
<asp:Button ID="Button1" runat="server"
</head>
Text="Write Cookie"
<body>
onclick="Button1_Click" />&nbsp;&nbsp;&nbsp;
<form id="form1" runat="server">
<asp:Button ID="Button6" runat="server"
<div style="height: 733px; width: 965px">
OnClick="Button6_Click" Text="Read Cookies" />
<asp:Label ID="Label1" runat="server" Font-
<br/><br/>
Bold="True" Font-Size="Larger" Text="Hidden Form
<br/>
Field "></asp:Label>
<asp:Label ID="Label6" runat="server"
<br />
Text="Label"></asp:Label>
<asp:HiddenField ID="HiddenField1"
<br/>
runat="server" Value="10000" />
</div>
<br />
</form>
<asp:Button ID="Button2" runat="server"
</body>
OnClick="Button2_Click" Text="View Hidden Form
</html>
Field" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label2" runat="server"
Text="Label"></asp:Label> [Link]:
<br />
<br /> using System;
<asp:Label ID="Label3" runat="server" Font- using [Link];
Bold="True" Font-Size="Larger" using [Link];
Text="ViewState"></asp:Label> using [Link];
<br /> using [Link];
<br /> using [Link];
<asp:Button ID="Button3" runat="server"
OnClick="Button3_Click" Text="Create ViewState" /> namespace ClientsideSessionManagement
&nbsp; {
<asp:TextBox ID="TextBox1" public partial class ClientsideSessionManagement :
runat="server"></asp:TextBox> [Link]
<br /> {
<br /> protected void Page_Load(object sender,
<asp:Button ID="Button4" runat="server" EventArgs e)
OnClick="Button4_Click" Text="Get View State" /> {
<br /> //[Link] =
<br /> "[Link]?cookie = " +
<asp:Label ID="Label4" runat="server" [Link]();
Text="Label"></asp:Label> }
<br />

Name: Arif Shaikh Roll no. 39


protected void Button2_Click(object sender, [Link]
EventArgs e)
{ <%@ Page Language="C#" AutoEventWireup="true"
[Link] = [Link]; CodeBehind="[Link]"
} Inherits="ClientsideSessionManagement.WebForm2"
%>
protected void Button1_Click(object sender,
EventArgs e) <!DOCTYPE html>
{
[Link]["name"].Value = <html xmlns="[Link]
[Link]; <head runat="server">
[Link]["name"].Expires = <title></title>
[Link](1); </head>
[Link] = "Cookie Created"; <body>
[Link] = ""; <form id="form1" runat="server">
} <div>
<asp:TextBox ID="TextBox1"
protected void Button3_Click(object sender, runat="server"></asp:TextBox>
EventArgs e) &nbsp;&nbsp;&nbsp;
{ <asp:Button ID="Button1" runat="server"
ViewState["userid"] = [Link]; OnClick="Button1_Click" Text="Get Query String" />
[Link]("ViewState Created <br />
Successfully"); </div>
} </form>
</body>
protected void Button4_Click(object sender, </html>
EventArgs e)
{
if (ViewState["userid"] != null) [Link]
{
[Link] = using System;
ViewState["userid"].ToString(); using [Link];
} using [Link];
} using [Link];
using [Link];
protected void Button5_Click(object sender, using [Link];
EventArgs e)
{ namespace ClientsideSessionManagement
{
[Link]("[Link]?data=" public partial class WebForm2 : [Link]
+ [Link]); {
} protected void Page_Load(object sender,
EventArgs e)
protected void Button6_Click(object sender, {
EventArgs e)
{ }
if ([Link]["name"] == null)
{ protected void Button1_Click(object sender,
[Link] = "No cookie found"; EventArgs e)
} {
else if([Link]["data"]!=null)
{ {
[Link] = string data =
[Link]["name"].Value; [Link]["data"].ToString();
} [Link] = data;
} }
} }
} }
}

Name: Arif Shaikh Roll no. 39


Design:

Output:

Practical No. 30

Aim: Design a session-based login systems


where users are redirected to a dashboard
upon successful login

[Link]:
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="[Link]"
Inherits="[Link]" %>

Name: Arif Shaikh Roll no. 39


<!DOCTYPE html> {
<html> string username = [Link];
<head> string password = [Link];
<title>Login</title>
</head> // Hardcoded authentication (Replace with
<body> database check)
<form id="form1" runat="server" > if (username == "admin" && password ==
<asp:Label ID="lblUsername" runat="server" "password")
Text="Username:"></asp:Label> {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Session["User"] = username;
<asp:TextBox ID="txtUsername" [Link]("[Link]");
runat="server"></asp:TextBox> }
<br /> else
<br /> {
<asp:Label ID="lblPassword" runat="server" [Link] = "Invalid username or
Text="Password:"></asp:Label> password.";
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<asp:TextBox ID="txtPassword" runat="server" }
TextMode="Password"></asp:TextBox> }
<br /> }
<br />

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb Design:
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btnLogin" runat="server"
Text="Login" OnClick="btnLogin_Click"
style="margin-left: 0px" Width="110px" />
&nbsp;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="lblMessage" runat="server"
ForeColor="Red"></asp:Label>
</form>
</body>
</html>

[Link]:
using System;
using [Link]; [Link]
using [Link];
using [Link]; <%@ Page Language="C#" AutoEventWireup="true"
using [Link]; CodeBehind="[Link]"
using [Link]; Inherits="[Link]"
%>
namespace ServersideSessionManagement
{ <!DOCTYPE html>
public partial class Login : [Link] <html>
{ <head>
protected void Page_Load(object sender, <title>Dashboard</title>
EventArgs e) </head>
{ <body>
<form id="form1" runat="server">
} <asp:Label ID="lblWelcome" runat="server"
ForeColor="Green"></asp:Label>
protected void btnLogin_Click(object sender, <br />
EventArgs e) <br />

Name: Arif Shaikh Roll no. 39


<asp:Button ID="btnLogout" runat="server" Practical No. 31
Text="Logout" OnClick="btnLogout_Click" />
</form> Design [Link] Web Application to
</body> demonstrate Ajax controls.
</html>

[Link]
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];

namespace ServersideSessionManagement
{
public partial class Dashboard : [Link]
{
protected void Page_Load(object sender,
EventArgs e)
{
if (Session["User"] == null)
{
[Link]("[Link]");
}
else
{
[Link] = "Welcome, " +
Session["User"].ToString();
}
}

protected void btnLogout_Click(object sender,


EventArgs e)
{
[Link](); <%@ Page Language="C#" AutoEventWireup="true"
[Link]("[Link]"); CodeBehind="[Link]"
} Inherits="[Link]" %>
}
} <!DOCTYPE html>

<html xmlns="[Link]
Design: <head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

Enter name:-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
<br /> <br />

Name: Arif Shaikh Roll no. 39


Enter email:- <asp:Label ID="Label3"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb runat="server"></asp:Label>
sp;&nbsp;&nbsp;&nbsp; <br />
<asp:TextBox ID="TextBox2" <br />
runat="server"></asp:TextBox> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
<br /> <br /> sp;&nbsp; Phone :&nbsp;
<asp:Label ID="Label4"
Enter phone no:- runat="server"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </form>
<asp:TextBox ID="TextBox3" runat="server"> </body>
</asp:TextBox> </html>
<br /> <br />

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb [Link]
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using System;
<asp:Button ID="Button1" runat="server" using [Link];
onclick="Button1_Click" Text="SUBMIT" /> using [Link];
<br /> <br /> using [Link];
using [Link];
<asp:ScriptManager ID="ScriptManager1" using [Link];
runat="server"></asp:ScriptManager>
namespace AJAXControlDemo
<asp:UpdatePanel ID="UpdatePanel1" {
runat="server"> public partial class AJAXControls :
<ContentTemplate> [Link]
<asp:Timer ID="Timer1" runat="server" {
Interval="1000" OnTick="Timer1_Tick"> protected void Page_Load(object sender,
</asp:Timer> EventArgs e)
<br /> {

<asp:Panel ID="Panel1" runat="server" }


BackColor="#3399FF" style="margin-left: 40px"
Width="168px" Height="62px" BorderStyle="Double"> protected void Button1_Click(object sender,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EventArgs e)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb {
sp;&nbsp;&nbsp;&nbsp; [Link] = [Link];
<br /> [Link] = [Link];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Link] = [Link];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb }
sp;&nbsp;&nbsp;

<asp:Label ID="Label1" runat="server" protected void Timer1_Tick(object sender,


Text="Label"> </asp:Label> EventArgs e)
</asp:Panel> {
</ContentTemplate> [Link] =
</asp:UpdatePanel> [Link]();
}
</div> <br /> }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;
Name :
<asp:Label ID="Label2" Output :
runat="server"></asp:Label>
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp; Email ID :

Name: Arif Shaikh Roll no. 39


<asp:TextBox ID="txtUserId"
runat="server"></asp:TextBox>
&nbsp;
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btnFetch" runat="server"
Text="Fetch Details" OnClick="btnFetch_Click" />

<br />

<asp:UpdatePanel ID="UpdatePanel1"
runat="server">
<ContentTemplate>
<asp:Label ID="lblUserDetails"
runat="server" ForeColor="Green"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

Practical No. 32
Implement an AJAX-enabled web form to fetch
user details without reloading the page.

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


CodeBehind="[Link]" using System;
Inherits="[Link]" using [Link];
%> using [Link];
using [Link];
<!DOCTYPE html> using [Link];
<html> using [Link];
<head>
<title>AJAX Fetch User Details</title> namespace AJAXEnabledApplication
</head> {
<body> public partial class FetchUserDetails :
<form id="form1" runat="server"> [Link]
<asp:ScriptManager ID="ScriptManager1" {
runat="server"></asp:ScriptManager> private Dictionary<int, string> users = new
Dictionary<int, string>
<br /> {
{1, "John Doe, johndoe@[Link]"},
<asp:Label ID="lblUserId" runat="server" {2, "Jane Smith, janesmith@[Link]"},
Text="Enter User ID:"></asp:Label> {3, "Mike Johnson,
mikejohnson@[Link]"}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb };
sp;

Name: Arif Shaikh Roll no. 39


protected void Page_Load(object sender, <%@ Page Language="C#" AutoEventWireup="true"
EventArgs e) CodeBehind="[Link]"
{ Inherits="SimpleTo_DoListusingAJAXControls.To_Do
List" %>
}
<!DOCTYPE html>
protected void btnFetch_Click(object sender, <html>
EventArgs e) <head>
{ <title>AJAX To-Do List</title>
if ([Link]([Link], out int userId) </head>
&& [Link](userId)) <body>
{ <form id="form1" runat="server">
[Link] = $"User Details: <asp:ScriptManager ID="ScriptManager1"
{users[userId]}"; runat="server"></asp:ScriptManager>
}
else <br />
{
[Link] = "User not found."; <asp:Label ID="lblTask" runat="server"
} Text="Enter Task:"></asp:Label>
} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
} &nbsp;&nbsp;
} <asp:TextBox ID="txtTask"
runat="server"></asp:TextBox>
Output: &nbsp;
<br />
<br />
<asp:Button ID="btnAdd" runat="server"
Text="Add Task" OnClick="btnAdd_Click" />

<br />

<asp:UpdatePanel ID="UpdatePanel1"
runat="server">
<ContentTemplate>
<asp:BulletedList ID="lstTasks"
runat="server"></asp:BulletedList>
<br />
<asp:Button ID="btnClear" runat="server"
Text="Clear Tasks" OnClick="btnClear_Click" />
</ContentTemplate>
Practical No. 33 </asp:UpdatePanel>
</form>
Develop a simple to-do list application using </body>
AJAX controls and update panels. </html>

[Link]
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];

namespace SimpleTo_DoListusingAJAXControls
{

Name: Arif Shaikh Roll no. 39


public partial class To_DoList : [Link] Practical No. 34
{
protected void Page_Load(object sender, Aim: Demonstrate the use of [Link] file
EventArgs e) for handling application-level events
{
if (!IsPostBack) [Link]:
{
Session["Tasks"] = new List<string>(); <%@ Application Codebehind="[Link]"
} Inherits="[Link]"
} Language="C#" %>
<script runat="server">
protected void btnAdd_Click(object sender, void Application_Start(object sender, EventArgs e)
EventArgs e) {
{ // Runs when the application starts
List<string> tasks = Application["TotalVisitors"] = 0;
(List<string>)Session["Tasks"]; Application["ActiveUsers"] = 0;
if (![Link]([Link])) }
{
[Link]([Link]); void Session_Start(object sender, EventArgs e)
Session["Tasks"] = tasks; {
[Link] = ""; // Runs when a new session starts
} if (Application["TotalVisitors"] == null)
LoadTasks(); {
} Application["TotalVisitors"] = 0;
}
protected void btnClear_Click(object sender, Application["TotalVisitors"] =
EventArgs e) (int)Application["TotalVisitors"] + 1;
{
Session["Tasks"] = new List<string>(); if (Application["ActiveUsers"] == null)
LoadTasks(); {
} Application["ActiveUsers"] = 0;
private void LoadTasks() }
{ Application["ActiveUsers"] =
[Link](); (int)Application["ActiveUsers"] + 1;
List<string> tasks = }
(List<string>)Session["Tasks"];
foreach (string task in tasks) void Application_Error(object sender, EventArgs e)
{ {
[Link](task); // Handles global errors and logs them
} Exception ex = [Link]();
}
} [Link]([Link]("~/Erro
} [Link]"), [Link]());
}
Output:
void Session_End(object sender, EventArgs e)
{
// Runs when a session ends
Application["ActiveUsers"] =
(int)Application["ActiveUsers"] - 1;
}

void Application_End(object sender, EventArgs e)


{
// Runs when the application shuts down
}
</script>

Name: Arif Shaikh Roll no. 39


Design:
[Link]:
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="[Link]"
Inherits="[Link]" %>

<!DOCTYPE html>
<html>
<head>
<title>[Link] Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="lblVisitors"
runat="server"></asp:Label>
<br /> Output:
<br />
<asp:Label ID="lblActiveUsers"
runat="server"></asp:Label>
</form>
</body>
</html>

[Link]:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];

namespace UseofGlobalasaxFileDemo
{
public partial class Globalasax : [Link]
{
protected void Page_Load(object sender,
EventArgs e)
{
[Link] = "Total Visitors: " +
Application["TotalVisitors"].ToString();
[Link] = "Active Users: " +
Application["ActiveUsers"].ToString();
}
}
}

Name: Arif Shaikh Roll no. 39

You might also like