5c. Create a web application to demonstrate various states of ASP.NET Pages

Program:


Default.aspx


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>
    <h3>View Demo state</h3>
    Page counter:
   
        <asp:Label ID="lb1" runat="server" Text="Label"></asp:Label>
        <br />
        <br />
        <asp:Button ID="btn" runat="server" onclick="btn_Click"
            onclientclick="btnIncrement_Click" Text="add count" />
   
    </div>
    </form>
</body>
</html>



Default.aspx.cs

using System;
using System.Configuration;
using System.Data;
using System.Linq;
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;

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


    public int counter
    {
        get
        {
            if (ViewState["pcounter"] != null)
            {
                return ((int)ViewState["pcounter"]);
            }
            else
            {
                return 0;
            }
        }

        set
        {
            ViewState["pcounter"] = value;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        lb1.Text = counter.ToString();
        counter++;
    }
    protected void btn_Click(object sender, EventArgs e)
    {
     }

}










Comments