问题
if i set EnableViewState="false"
then also input data is maintain after postback at the time of using control like
- textbox
- radio button
- checkbox
- etc.
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" />
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
回答1:
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.
回答2:
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
Understanding ASP.NET View State
View State for TextBox and other controls that implement IPostBackDataHandler
How do I disable viewstate for a specific control?
来源:https://stackoverflow.com/questions/5748354/asp-net-page-controls-and-viewstate