aspx 页面中 EnableViewState="false" 的效果

本文探讨了在ASP.NET页面指令中设置EnableViewState=false后,页面回发时DropDownList等控件值丢失的问题,以及Web控件的AutoPostBack属性在禁用ViewState情况下的行为变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

通说页面关闭了ViewSate以后会提高页面的访问速度,今天试了一下,结果发现了一个奇怪的现象,在这里说出来,和大家

分享一下。

ViewState可是让我们像使用 Session一样 向ViewState中添加需要传递的变量,保存需要保留的信息。

当我们在页面的指令中加入 EnableViewState="false" 时 我们在后台cs页中定义的ViewState都会失去作用,

还有一个更值得我们需要注意的就是,不单单是我们自己定义的ViewState不能使用,一些控件的值在页面的回发之后值也会消失。

举个例子就是DropDownList控件,EnableViewState="false"的状态下页面的回发就不能获取到DropDownList中的值

一些Web控件中的 AutoPostBack 属性开启后 在页面做了回发以后依然可以保存控件之前的值,就是使用的ViewState的

这个特性。

一个小小的细节,希望可以帮助一些有这方面需要的朋友。

转载于:https://www.cnblogs.com/chubbyjeffrey/archive/2011/05/30/2063366.html

只有web.config:内容如下哪里是提高画面质量的选项:<?xml version="1.0" encoding="UTF-8"?> <configuration> <!-- CAUTION! logging requires the ASP.NET IIS worker process to have write permission to the "log" folder. Among other options, you may grant the myrtille application pool ("IIS AppPool\MyrtilleAppPool") write permission to it (normally automatically set by the myrtille installer). --> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, Log4net" /> <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <section name="Myrtille.Web.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </sectionGroup> </configSections> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-1.5.1.25624" newVersion="1.5.2.14234" /> </dependentAssembly> </assemblyBinding> </runtime> <log4net> <root> <level value="DEBUG" /> <appender-ref ref="LogFileAppender" /> </root> <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender"> <param name="File" value="log\Myrtille.Web.log" /> <param name="AppendToFile" value="true" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="10" /> <maximumFileSize value="10MB" /> <staticLogFileName value="true" /> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" /> </layout> </appender> </log4net> <system.diagnostics> <trace autoflush="true" indentsize="4"> <listeners> <add name="Log4netTraceListener" type="Myrtille.Log.Log4netTraceListener, Myrtille.Common"> <!-- trace level (Information, Warning or Error). CAUTION! Information level will hinder performance --> <filter type="Myrtille.Log.Log4netTraceFilter, Myrtille.Common" initializeData="Error" /> </add> <!-- disable output window traces. CAUTION! enabling the default output window will hinder performance --> <remove name="Default" /> </listeners> </trace> <!-- enable the lines below for WCF tracing (caution as it will hinder performance). Use SvcTraceViewer.exe as viewer --> <!-- <sources> <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true"> <listeners> <add name="xml" /> </listeners> </source> <source name="System.ServiceModel.MessageLogging"> <listeners> <add name="xml" /> </listeners> </source> </sources> <sharedListeners> <add initializeData="log\Myrtille.Web.svclog" type="System.Diagnostics.XmlWriterTraceListener" name="xml" /> </sharedListeners> --> </system.diagnostics> <system.web> <compilation defaultLanguage="C#" targetFramework="4.5" /> <!-- handle file upload/download up to 1GB. maxRequestLength is measured in kilobytes and executionTimeout in seconds --> <!-- handle querystrings up to 32KB (default 2KB). this can prove useful with large XHRs in HTML4 mode --> <httpRuntime requestValidationMode="4.5" targetFramework="4.5" maxRequestLength="1048576" maxQueryStringLength="32768" executionTimeout="360000" /> <pages enableViewState="false" validateRequest="false" enableEventValidation="false" clientIDMode="AutoID" /> <authorization> <allow users="*" /> </authorization> <authentication mode="None" /> <!-- CAUTION! cookieless="UseUri" allows multiple connections/tabs but, as the http session id is passed into the url, it also implies a risk of session spoofing to mitigate that risk, an authentication cookie is stored into the browser initiating the http session; any other client accessing the http session without it will be rejected please note that, even if the http session is cookieless, this mechanism requires cookies to be enabled client side the "cookieless=" attribute is really confusing because it's in fact the method used by the browser to send the http session id... and using a cookie is the standard way to do it if using myrtille within iframe(s) on a same page, cookieless="UseUri" must be used --> <sessionState mode="InProc" cookieless="UseUri" timeout="60" /> <!--<sessionState mode="InProc" cookieless="UseCookies" cookieName="AuthSecToken" timeout="60"/>--> <globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="auto" uiCulture="auto" /> </system.web> <system.webServer> <defaultDocument> <files> <clear /> <add value="Default.aspx" /> </files> </defaultDocument> <urlCompression doDynamicCompression="false" /> <staticContent> <mimeMap fileExtension=".webp" mimeType="image/webp" /> </staticContent> <security> <requestFiltering> <!-- handle file upload/download up to 1GB. maxAllowedContentLength is measured in bytes --> <!-- handle querystrings up to 32KB (default 2KB). this can prove useful with large XHRs in HTML4 mode --> <requestLimits maxAllowedContentLength="1073741824" maxQueryString="32768" /> </requestFiltering> </security> <handlers> <add path="/handlers/SocketHandler.ashx" verb="*" name="SocketHandler" type="Myrtille.Web.SocketHandler" /> <add path="/handlers/AudioSocketHandler.ashx" verb="*" name="AudioSocketHandler" type="Myrtille.Web.AudioSocketHandler" /> <add path="/handlers/EventSourceHandler.ashx" verb="*" name="EventSourceHandler" type="Myrtille.Web.EventSourceHandler" /> <add path="/handlers/LongPollingHandler.ashx" verb="*" name="LongPollingHandler" type="Myrtille.Web.LongPollingHandler" /> </handlers> </system.webServer> <system.serviceModel> <client> <endpoint address="http://localhost:8080/Myrtille/RemoteSessionProcess" binding="wsDualHttpBinding" bindingConfiguration="wsDualHttpBindingCallback" contract="Myrtille.Services.Contracts.IRemoteSessionProcess" /> <endpoint address="http://localhost:8080/Myrtille/FileStorage" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingFileStream" contract="Myrtille.Services.Contracts.IFileStorage" /> <endpoint address="http://localhost:8080/Myrtille/PrinterService" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingFileStream" contract="Myrtille.Services.Contracts.IPrinterService" /> <endpoint address="http://localhost:8080/Myrtille/MFAAuthentication" binding="basicHttpBinding" contract="Myrtille.Services.Contracts.IMFAAuthentication" /> <endpoint address="http://localhost:8080/Myrtille/EnterpriseService" binding="basicHttpBinding" contract="Myrtille.Services.Contracts.IEnterpriseService" /> <endpoint address="http://localhost:8080/Myrtille/ApplicationPoolService" binding="basicHttpBinding" contract="Myrtille.Services.Contracts.IApplicationPoolService" /> </client> <bindings> <wsDualHttpBinding> <binding name="wsDualHttpBindingCallback" receiveTimeout="infinite" maxReceivedMessageSize="2147483647"> <security mode="None" /> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> <reliableSession inactivityTimeout="infinite" /> </binding> </wsDualHttpBinding> <basicHttpBinding> <!-- buffer size: 64KB; max file size: 1GB --> <binding name="basicHttpBindingFileStream" transferMode="Streamed" messageEncoding="Mtom" maxBufferSize="65536" maxReceivedMessageSize="1073741824" closeTimeout="infinite" openTimeout="infinite" receiveTimeout="infinite" sendTimeout="infinite"> <security mode="None" /> </binding> </basicHttpBinding> </bindings> <!-- enable the lines below for WCF tracing (caution as it will hinder performance). Use SvcTraceViewer.exe as viewer --> <!-- <diagnostics> <messageLogging logEntireMessage="true" maxMessagesToLog="300" logMessagesAtServiceLevel="true" logMalformedMessages="true" logMessagesAtTransportLevel="true" /> </diagnostics> --> </system.serviceModel> <applicationSettings> <Myrtille.Web.Properties.Settings> <setting name="ConnectionServiceUrl" serializeAs="String"> <value>http://localhost:8008/MyrtilleAdmin/ConnectionService/</value> </setting> </Myrtille.Web.Properties.Settings> </applicationSettings> <appSettings> <!-- disable Visual Studio SignalR --> <add key="vs:EnableBrowserLink" value="false" /> <!-- disable Visual Studio Page Inspector --> <add key="PageInspector:ServerCodeMappingSupport" value="Disabled" /> <!-- providing access to the remote clipboard could be a security issue, it can be disabled below --> <add key="AllowRemoteClipboard" value="true" /> <!-- allow file transfer (requires a domain to be specified on connect) --> <add key="AllowFileTransfer" value="true" /> <!-- allow print download (through a pdf virtual printer). requires the "Myrtille PDF" printer to be installed --> <add key="AllowPrintDownload" value="true" /> <!-- allow remote session sharing (the session is broadcasted to all guests; read/write access is granted individually) --> <add key="AllowSessionSharing" value="true" /> <!-- allow audio plaback --> <add key="AllowAudioPlayback" value="true" /> <!-- share a session by url, with owner rights. set to false to disable and provide a session url spoofing protection. requires cookieless="UseUri" session state (system.web/sessionState section above) --> <!-- if a session is shared by url between different clients, each client is identified by a unique key instead of the http session id --> <add key="AllowShareSessionUrl" value="true" /> <!-- client ip protection --> <add key="ClientIPTracking" value="false" /> <!-- if the browser window/tab of the remote session owner is closed without disconnecting first, or if the connection is lost, delay (ms) before the remote session is disconnected by the gateway. value must be greater than "browserPulseInterval" defined into config.js (default 10 secs). 0 to disable --> <!-- this comes in addition but does not replace the session idle timeout, defined at the RDS level, which will disconnect the session after no user inputs are received for a given time, independently of Myrtille --> <add key="ClientIdleTimeout" value="0" /> <!-- audio buffer. improves the audio quality at the expense of a slight latency --> <add key="AudioBuffering" value="true" /> <!-- show or hide the toolbar (you can hide it if using your own UI) --> <add key="ToolbarEnabled" value="true" /> <!-- connect from a login page or url (you can disable it if using a connection API) --> <add key="LoginEnabled" value="true" /> <!-- if login is enabled, url of the login page (change it if using your own page or leave empty to use the default page) --> <add key="LoginUrl" value="" /> <!-- recycle the application pool when there is no active remote session; not applicable if using the enterprise mode --> <add key="IdleAppPoolRecycling" value="false" /> </appSettings> </configuration>
最新发布
07-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值