惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
P
Proofpoint News Feed
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
The Last Watchdog
The Last Watchdog
F
Fortinet All Blogs
S
Schneier on Security
Help Net Security
Help Net Security
Security Archives - TechRepublic
Security Archives - TechRepublic
C
Check Point Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
I
InfoQ
T
The Blog of Author Tim Ferriss
Cisco Talos Blog
Cisco Talos Blog
Stack Overflow Blog
Stack Overflow Blog
T
Troy Hunt's Blog
人人都是产品经理
人人都是产品经理
T
Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cyber Attacks, Cyber Crime and Cyber Security
雷峰网
雷峰网
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
Forbes - Security
Forbes - Security
Vercel News
Vercel News
S
Security Affairs
美团技术团队
P
Privacy & Cybersecurity Law Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Jina AI
Jina AI
Spread Privacy
Spread Privacy
Attack and Defense Labs
Attack and Defense Labs
IT之家
IT之家
U
Unit 42
Recorded Future
Recorded Future
W
WeLiveSecurity
PCI Perspectives
PCI Perspectives
P
Palo Alto Networks Blog
H
Hacker News: Front Page
S
Security @ Cisco Blogs
博客园 - 【当耐特】

博客园 - 北极冰点水

如何用C#代码设置文件的附加属性啊 例如author, subject 这些啊 在.NET中使TextBox只能输入数字的方法(key 和 clipboardData) - 北极冰点水 怎样在XML中使用&和字符 ViewState深入,Textbox,Checkbox,CheckboxList,RadioButtonList 不能禁止ViewState 什么是One-Click技术 未将对象引用到对象的实例 asp.net执行.sql文件 和 Cmd 模式执行sql文件 - 北极冰点水 后期维护成本 用.net开发不同操作系统下应用的winform的size大小问题 怎样让用户可以跟踪查询数据库数据变化 在MembershipProvider中,现在的版本中MobileAlias 是没用的 也谈下vs2005中的gridview Vs2005 调试状态下的异常处理是比2003要好多了,布局图片也漂亮 vs2005 Gridview 得问题??? vs2005的数据库连接问题 2.0 Master Page C# 的 Delegate Type 安装SqlServer2005 Express Edit版 和 Vs 2005 CTP版 快速”格式化和常规格式化之间的区别
textbox web控件 根本无视enableviewsate 是否true 或者false, 依然能够相应用户的输入
北极冰点水 · 2006-11-21 · via 博客园 - 北极冰点水

在ASP.Net中WebForm控件有个EnableViewState属性。这个属性究竟有什么用。在VS的hint: Whether the control automatically saves its state for use in round-trips. 原理就是ASP.NET引用了viewstate的机制。在服务器端保存了网页各个控件及页面的状态,这其中包括各个控件在页面上的布局,和他们各自的属性。这些值就保存在ViewState下。我们可以观察Aspx页面的html源代码,假设这个页面上有一个button按钮,和一个listBox控件,html文件如下:

<input type="hidden" name="__VIEWSTATE" value="dDwzODYzNDM5NTU7Oz7FvviJbq45bDa7QJaumIiOhZ8mOQ==" />

 <input type="submit" name="Button1" value="Button" id="Button1" style="height:40px;width:96px;Z-INDEX: 101; LEFT: 200px; POSITION: absolute; TOP: 240px" />
 <select name="ListBox1" size="4" id="ListBox1" style="width:152px;Z-INDEX: 102; LEFT: 176px; POSITION: absolute; TOP: 120px"></select>

其值是一长串字符。类型为“hidden”。这个值记录的就是各个控件和页面的状态信息。当用户对页面进行相关操作的时候,状态值发生改变,并将改变的值传递给服务器端。服务器端在比较改变后的状态值和初始值之间的区别,以响应具体的请求。

一旦页面的控件很多,这种频繁的传递控件状态值对网络的消耗是很大的,因此,ASP.Net提供了EnableViewState属性,系统默认的值为true。当设置为true时,在传递状态值时就包括该控件;如果设置为false,则传递状态值时则不包括它。既然状态值不包括该控件,则客户端对它进行的操作,服务器端是不响应的。

我们可以做个实验,在Button1_Click事件中,编写代码:

ListBox.Items.Add(”客户端点击按钮一次!”);

此时运行该应用程序,单击网页上的按钮,在ListBox中会添加内容,不断地单击,内容则不断添加。如果我们将ListBox的EnableViewState属性改为false时,不断单击按钮,则只能添加一次。

这样有什么好处呢?如果我们在开发Web应用程序时,某些控件是不需要接受用户的操作或只需要接受一次操作的时候,我们可以将这些控件的EnableViewState属性改为false,这样可以优化我们的程序,提高网络访问的速度.

按照道理这个原理对于textbox也是同样的,但是在实验过程中发现textbox 根本就无视enableviewsate 是否true 或者false.Textbox2依然能够相应用户的输入. 源码:aspx
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" enableViewState="False"%> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" enableViewState="False"%> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" enableViewState="False"%> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" enableViewState="False"%> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" enableViewState="False"%> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" enableViewState="False"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
  <title>WebForm1</title>
  <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
  <meta name="CODE_LANGUAGE" Content="C#">
  <meta name="vs_defaultClientScript" content="JavaScript">
  <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
  </HEAD>
 <body MS_POSITIONING="GridLayout">
  <form id="Form1" method="post" runat="server">
   <asp:TextBox id="TextBox1" style="Z-INDEX: 100; LEFT: 280px; POSITION: absolute; TOP: 120px"
    runat="server" Text="Build.Com" EnableViewState="False">Build.Com</asp:TextBox>
<asp:TextBox id=TextBox3 style="Z-INDEX: 105; LEFT: 280px; POSITION: absolute; TOP: 200px" runat="server" EnableViewState="False" Text=""></asp:TextBox>
   <asp:TextBox id="TextBox2" style="Z-INDEX: 102; LEFT: 280px; POSITION: absolute; TOP: 168px"
    runat="server" Text="" EnableViewState="False"></asp:TextBox>
   <asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 360px; POSITION: absolute; TOP: 240px" runat="server"
    Text="Button" EnableViewState="False"></asp:Button>
   <asp:ListBox id="ListBox1" style="Z-INDEX: 104; LEFT: 144px; POSITION: absolute; TOP: 184px"
    runat="server" EnableViewState="False"></asp:ListBox>
  </form>
 </body>
</HTML>

CS:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication1
{
 /// <summary>
 /// Summary description for WebForm1.
 /// </summary>
 public class WebForm1 : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.TextBox TextBox1;
  protected System.Web.UI.WebControls.Button Button1;
  protected System.Web.UI.WebControls.ListBox ListBox1;
  protected System.Web.UI.WebControls.TextBox TextBox2;
  protected System.Web.UI.WebControls.TextBox TextBox3;
 
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   // Put user code to initialize the page here
   
  }

  #region Web Form Designer generated code
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: This call is required by the ASP.NET Web Form Designer.
   //
   InitializeComponent();
   //base.OnInit(e);
  }
  
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {   
   this.Button1.Click += new System.EventHandler(this.Button1_Click);
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion

  private void Button1_Click(object sender, System.EventArgs e)
  {
   ListBox1.Items.Add("客户端点击按钮一次!");
   TextBox3.Text = TextBox2.Text + TextBox1.Text;

  }
 }
}