{"id":237666,"date":"2022-03-27T09:01:09","date_gmt":"2022-03-27T01:01:09","guid":{"rendered":"https:\/\/gulass.cn\/?p=237666"},"modified":"2022-03-14T10:03:39","modified_gmt":"2022-03-14T02:03:39","slug":"keeping-viewstate-introduction","status":"publish","type":"post","link":"https:\/\/gulass.cn\/keeping-viewstate-introduction.html","title":{"rendered":"ASP.NET Web \u7a97\u4f53- \u4fdd\u6301 ViewState\u7b80\u4ecb"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u901a\u8fc7\u5728Web \u8868\u5355\u4e2d\u7ef4\u5ea6\u5bf9\u8c61\u7684 ViewState\uff08\u89c6\u56fe\u72b6\u6001\uff0c\u60a8\u53ef\u4ee5\u7701\u53bb\u5927\u91cf\u7684\u7f16\u7801\uff09\u5de5\u4f5c\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u7ef4ViewState\uff08\u89c6\u56fe\u72b6\u6001\uff09<\/strong><\/div>\n

\u5728\u7ecf\u5178\u7684 ASP \u4e2d\uff0c\u5f53\u4e00\u4e2a\u8868\u5355\u88ab\u63d0\u4ea4\u65f6\uff0c\u6240\u6709\u7684\u8868\u5355\u503c\u90fd\u4f1a\u88ab\u6e05\u7a7a\u3002\u5047\u8bbe\u60a8\u63d0\u4ea4\u4e86\u5f88\u591a\u4fe1\u606f\uff0c\u8fd4\u56de\u5230\u670d\u52a1\u5668\u7684\u4e00\u4e2a\u9519\u8bef\u3002\u8fd4\u56de\uff0c\u7136\u540e\u60a8\u5f00\u59cb\u51fa\u73b0...<\/p>\n

\u5728 ASP .NET \u4e2d\uff0c\u5f53\u4e00\u4e2a\u8868\u5355\u88ab\u63d0\u4ea4\u65f6\uff0c\u8868\u5355\u503c\u4f1a\u4e00\u8d77\u51fa\u73b0\u5728\u6d4f\u89c8\u5668\u4e2d\u3002\u56e0\u4e3a\u5982\u4f55\u88ab\u5904\u7406\u7684\u5462\uff1f\u670d\u52a1\u5668\u4ee3\u7801\u7684\u65f6\u5019\u81ea\u52a8\u5b9a\u4e49\u5b83\u7684\u72b6\u6001\u3002\u5230\u8fd9\u4e2a\u72b6\u6001\u662f\u5728<\/p>\n

\u63a7\u4ef6\u7684\u6240\u6709\u9875\u9762\u4e0a\u653e\u7f6e\u4e00\u4e2a\u9690\u85cf\u57df\u7684\u3002\u6e90\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n
<form name=\"_ctl0\" method=\"post\" action=\"page.aspx\" id=\"_ctl0\">\r\n<input type=\"hidden\" name=\"__VIEWSTATE\"\r\nvalue=\"dDwtNTI0ODU5MDE1Ozs+ZBCF2ryjMpeVgUrY2eTj79HNl4Q=\" \/>\r\n.....some code\r\n<\/form><\/pre>\n

\u7ef4\u5ea6 ViewState \u662f ASP.NET Web Forms \u7684\u9ed8\u8ba4\u8bbe\u7f6e\u3002\u5982\u679c\u60a8\u4e0d\u60f3\u4fdd\u6301 ViewState\uff0c\u8bf7\u5728 .aspx \u9875\u9762\u9876\u90e8\u5305\u542b\u6307\u4ee4 <%@ Page EnableViewState=\"false\" %\u5c5e\u6027\uff0c\u6216\u8005\u5411\u63a7\u4ef6\u6dfb\u52a0 EnableViewState=\"false\" \u3002<\/p>\n

\u770b\u770b\u4e0b\u9762\u7684.aspx\u6587\u4ef6\u3002\u5b83\u5c55\u793a\u4e86\u7684\u8fd0\u884c\u65b9\u5f0f\u63d0\u4ea4\u6309\u94ae\u3002<\/p>\n

\u5b9e\u4f8b<\/strong><\/p>\n

<html>\r\n<body>\r\n<form action=\"demo_classicasp.aspx\" method=\"post\">\r\nYour name: <input type=\"text\" name=\"fname\" size=\"20\">\r\n<input type=\"submit\" value=\"Submit\">\r\n<\/form>\r\n<%\r\ndim fname\r\nfname=Request.Form(\"fname\")\r\nIf fname<>\"\" Then\r\nResponse.Write(\"Hello \" & fname & \"!\")\r\nEnd If\r\n%>\r\n<\/body>\r\n<\/html><\/pre>\n

\u4e0b\u9762\u662f\u65b0\u7684 ASP .NET\u3002\u5f53\u60a8\u63d0\u4ea4\u6309\u94ae\u65f6\uff0c\u8868\u5355\u503c\u4e0d\u4f1a\u88ab\u5220\u9664\uff1a<\/p>\n

\u5b9e\u4f8b<\/strong>
\n\u70b9\u51fb\u5b9e\u4f8b\u7684\u53f3\u4fa7\u6846\u67b6\u4e2d\u7684\u67e5\u770b\u4ee3\u7801\uff0c\u60a8\u4f1a\u770b\u5230 ASP .NET \u5df2\u7ecf\u5728\u8868\u5355\u4e2d\u6dfb\u52a0\u4e86\u4e00\u4e2a\u9690\u85cf\u57df\u6765\u7ef4\u5ea6 ViewState\u3002<\/p>\n

<script runat=\"server\">\r\nSub submit(sender As Object, e As EventArgs)\r\nlbl1.Text=\"Hello \" & txt1.Text & \"!\"\r\nEnd Sub\r\n<\/script>\r\n<html>\r\n<body>\r\n<form runat=\"server\">\r\nYour name: <asp:TextBox id=\"txt1\" runat=\"server\" \/>\r\n<asp:Button OnClick=\"submit\" Text=\"Submit\" runat=\"server\" \/>\r\n<p><asp:Label id=\"lbl1\" runat=\"server\" \/><\/p>\r\n<\/form>\r\n<\/body>\r\n<\/html><\/pre>\n<\/form>\n","protected":false},"excerpt":{"rendered":"

\u5728\u7ecf\u5178\u7684 ASP \u4e2d\uff0c\u5f53\u4e00\u4e2a\u8868\u5355\u88ab\u63d0\u4ea4\u65f6\uff0c\u6240\u6709\u7684\u8868\u5355\u503c\u90fd\u4f1a\u88ab\u6e05\u7a7a\u3002\u5047\u8bbe\u60a8\u63d0\u4ea4\u4e86\u5f88\u591a\u4fe1\u606f\uff0c\u8fd4\u56de\u5230\u670d\u52a1\u5668\u7684\u4e00\u4e2a\u9519\u8bef […]<\/p>\n","protected":false},"author":1470,"featured_media":237668,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-237666","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/237666","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1470"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=237666"}],"version-history":[{"count":3,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/237666\/revisions"}],"predecessor-version":[{"id":237671,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/237666\/revisions\/237671"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/237668"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=237666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=237666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=237666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}