<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="View_State_Practice_State_Management.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 105px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellpadding="3" cellspacing="3" class="auto-style1">
<tr>
<td class="auto-style2">USERNAME</td>
<td>
<asp:TextBox ID="UserTextBox" runat="server" Width="205px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">PASSWORD</td>
<td>
<asp:TextBox ID="PassTextBox" runat="server" Width="205px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td>
<asp:Button ID="SubmitButton" runat="server" Text="SUBMIT" Height="36px" OnClick="SubmitButton_Click" Width="95px"/>
<asp:Button ID="RestoreButton" runat="server" Text="RESTORE" Height="36px" Width="95px" OnClick="RestoreButton_Click"/>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Above File is View_State_Practice_State_Management\WebForm1.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace View_State_Practice_State_Management
{
public partial class WebForm1 : System.Web.UI.Page
{
string a, b;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RestoreButton_Click(object sender, EventArgs e)
{
if (ViewState["user"] != null)
{
UserTextBox.Text = ViewState["user"].ToString();
}
if (ViewState["pass"] != null)
{
PassTextBox.Text = ViewState["pass"].ToString();
}
}
protected void SubmitButton_Click(object sender, EventArgs e)
{
ViewState["user"] = UserTextBox.Text;
ViewState["pass"] = PassTextBox.Text;
UserTextBox.Text = string.Empty;
PassTextBox.Text = string.Empty;
Response.Redirect("WebForm2.aspx");
}
}
}
Above File is View_State_Practice_State_Management\WebForm1.aspx.cs
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="View_State_Practice_State_Management.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Username:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br/>
Password:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Restore" OnClick="Button1_Click"/>
</div>
</form>
</body>
</html>
Above File is View_State_Practice_State_Management\WebForm2.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace View_State_Practice_State_Management
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (ViewState["user"] != null)
{
TextBox1.Text = ViewState["user"].ToString();
}
if (ViewState["pass"] != null)
{
TextBox2.Text = ViewState["pass"].ToString();
}
}
}
}
Above File is View_State_Practice_State_Management\WebForm2.aspx.cs
Comments
Post a Comment