State
Management of View State_2 in ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ViewState2.aspx.cs" Inherits="ASPNETALL.ViewState2" %>
<!DOCTYPE html>
<html
xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Click Me" />
</div>
</form>
</body>
</html>
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Click Me" />
</form>
</body>
</html>
using System;
public partial class ViewState2 : System.Web.UI.Page
{
int ClickCount = 1;
if (!IsPostBack)
TextBox1.Text = "0";
}
if (ViewState["Clicks"] != null)
ClickCount = (int)ViewState["Clicks"] + 1;
TextBox1.Text = ClickCount.ToString();
ViewState["Clicks"] = ClickCount;
}
}
0 comments
Post a Comment