Friday, 27 January 2023

State Management of Hidden Form Field_2

 

State Management of Hidden Form Field_2
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HiddenField2.aspx.cs" Inherits="ASPNETALL.HiddenField2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table class="auto-style1">
            <tr>
                <td><h1> Hidden Form Field2</h1></td>
            </tr>
            <tr>
                <td>User Name :
                    <asp:Label ID="lblName" runat="server"></asp:Label>
                </td>
            </tr>
            <tr>
                <td>User Email :
                    <asp:Label ID="lblEmail" runat="server"></asp:Label>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

HiddenField2.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ASPNETALL
{
    public partial class HiddenField2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                Page lastPage = (Page)Context.Handler;
                if(lastPage is HiddenField1)
                {
                    lblName.Text = ((HiddenField1)lastPage).Name;
                    lblEmail.Text = ((HiddenField1)lastPage).Email;
                }
            }
        }
    }
}

0 comments

Post a Comment