खोज…


परिचय

व्यू स्टेट, राउंड ट्रिप्स के बीच पेज के मूल्य और नियंत्रण को संरक्षित करने की विधि है। यह एक पेज-लेवल स्टेट मैनेजमेंट तकनीक है। दृश्य स्थिति को डिफ़ॉल्ट रूप से चालू किया जाता है और सामान्य रूप से पृष्ठ पर हर नियंत्रण में डेटा को क्रमबद्ध करता है चाहे वह वास्तव में पोस्ट-बैक के दौरान उपयोग किया जाए।

वाक्य - विन्यास

  • ViewState ["NameofViewstate"] = "मूल्य";

उदाहरण

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>ViewState</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:TextBox runat="server" id="NameField" />
            <asp:Button runat="server" id="SubmitForm" onclick="SubmitForm_Click" text="Submit & set name" />
            <asp:Button runat="server" id="RefreshPage" text="Just submit" />
            <br /><br />
            Name retrieved from ViewState: <asp:Label runat="server" id="NameLabel" />
        </form> 
    </body>
    </html>

कोड के पीछे

using System;
using System.Data;
using System.Web;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(ViewState["NameOfUser"] != null)
            NameLabel.Text = ViewState["NameOfUser"].ToString();
        else
            NameLabel.Text = "Not set yet...";
    }

    protected void SubmitForm_Click(object sender, EventArgs e)
    {
        ViewState["NameOfUser"] = NameField.Text;
        NameLabel.Text = NameField.Text;
    }
}


Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow