ViewState.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ViewState.aspx.cs" Inherits="Learningneverend.ViewState" %>
<!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: 116px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr>
<td class="auto-style2">USERNAME</td>
<td>
<asp:TextBox ID="UserTextBox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">PASSWORD</td>
<td>
<asp:TextBox ID="PassTextBox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td>
<asp:Button ID="SubmitButton" runat="server" OnClick="SubmitButton_Click" Text="Submit" />
<asp:Button ID="RestoreButton" runat="server" OnClick="RestoreButton_Click" Text="Restore" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
ViewState.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Learningneverend
{
public partial class ViewState : 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;
}
}
}
0 Comments