开发者

Asp.net Page controls and viewstate

开发者 https://www.devze.com 2023-02-28 12:31 出处:网络
if i set EnableViewState=\"false\" then also input data is maintain after postback at the time of using control like

if i set EnableViewState="false" then also input data is maintain after postback at the time of using control like

So I just wanted to know bit internal things that if EnableViewState="false" then how input data is maintain after postback when we are using control like textbox, radio button checkbox etc. please discuss the internal issue.

Thanks.

here is my aspx code

<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="false" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %>

    <asp:TextBox ID="TextBox1" runat="server" 
        style="position: relative; top: 0px; left: 0px;"></asp:TextBox>


    <asp:TextBox ID="TextBox2" runat="server" 
        style="position: absolute; top: 66px; left: 11px; z-index: 1;"></asp:TextBox>


<asp:RadioButton ID="RadioButton1" runat="server" style="position: relative" />

    <asp:CheckBox ID="CheckBox1" runat="server" style="position: relative" />

 &nbsp;<asp:Button ID="Button1" runat="server" Text="Button" />

 </div>

</form>


Input data is maintained because the browser sends the input data to the server on every postback. For example, the textbox on the page has its text sent to the server every time there is a postback. Therefore, the text property does not need to be stored in view state in order to be remembered across postbacks.

For much more information on view state, check out this article: Understanding ASP.NET View State.


Take a look at Server controls persist their state when EnableViewState is set to False

Example: Consider backcolor setting programmatically. On postback, if viewstate is switched off, the background color of the Textbox control is lost. However, the text value of the control is maintained.

Note: If the backcolor was set directly in markup rather than in code behind, it would have persisted.

<form id="form1" runat="server">
<asp:TextBox ID="Textbox1" runat="server"  EnableViewState="false"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" EnableViewState="false" />
</form>

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        this.Textbox1.BackColor = Color.Yellow;

    }
}

Also refer

  1. Understanding ASP.NET View State

  2. View State for TextBox and other controls that implement IPostBackDataHandler

  3. How do I disable viewstate for a specific control?

0

精彩评论

暂无评论...
验证码 换一张
取 消