<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>State Management</title><link>http://forums.asp.net/22.aspx</link><description>Managing ASP.NET state - ViewState, Application, Session, etc. &lt;a href="http://aspadvice.com/SignUp/list.aspx?l=69&amp;c=17" target="_blank"&gt;Email List&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: ViewStae compression weired error</title><link>http://forums.asp.net/thread/3277730.aspx</link><pubDate>Mon, 06 Jul 2009 22:53:24 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3277730</guid><dc:creator>Nissan Fan</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3277730.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=22&amp;PostID=3277730</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;First of all, compressing the ViewState using this approach is very old school.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.codeguru.com/vb/vbnet30/article.php/c13931"&gt;http://www.codeguru.com/vb/vbnet30/article.php/c13931&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s a 5 line solution that tucks your ViewState Server Side.&amp;nbsp; BTW - you&amp;#39;d never actually want to Compress the ViewState as encrypted text like the ViewState doesn&amp;#39;t compress very well.&lt;/p&gt;
&lt;p&gt;Regards.&lt;/p&gt;</description></item><item><title>ViewStae compression weired error</title><link>http://forums.asp.net/thread/3270880.aspx</link><pubDate>Thu, 02 Jul 2009 09:27:53 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3270880</guid><dc:creator>harshalbhakta</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3270880.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=22&amp;PostID=3270880</wfw:commentRss><description>&lt;p&gt;hello experts,&lt;br /&gt;I have a weired problem regarding viewstate comression.&lt;br /&gt;I have implemented override methods LoadPageStateFromPersistenceMedium() and SavePageStateToPersistenceMedium(object viewState). &lt;br /&gt;Everything works fine. But the problem is when I hit Escape button twice in any textbox, the viewstate gets cleared and following error occures whle decompressing the viewstate in LoadPageStateFromPersistenceMedium.&lt;/p&gt;
&lt;p&gt;---------------------------&lt;br /&gt;Error&lt;br /&gt;---------------------------&lt;br /&gt;A Runtime Error has occurred.&lt;br /&gt;Do you wish to Debug?&lt;/p&gt;
&lt;p&gt;Line: 5&lt;br /&gt;Error: Sys.WebForms.PageRequestManagerServerErrorException: Value cannot be null.Parameter name: inputString&lt;br /&gt;---------------------------&lt;br /&gt;Yes&amp;nbsp;&amp;nbsp; No&amp;nbsp;&amp;nbsp; &lt;br /&gt;---------------------------&lt;/p&gt;
&lt;p&gt;My original code is:&lt;br /&gt;&lt;/p&gt;&lt;pre class="c-sharp" name="code"&gt;        protected override object LoadPageStateFromPersistenceMedium()
        {
            string viewState = Request.Form[&amp;quot;__VSTATE&amp;quot;];  //This remains empty strinf after hitting escape twice.
            byte[] bytes = Convert.FromBase64String(viewState);
            bytes = ViewStateCompressor.DecompressViewState(bytes);
            LosFormatter formatter = new LosFormatter();
            return formatter.Deserialize(Convert.ToBase64String(bytes));
        }

     
        protected override void SavePageStateToPersistenceMedium(object viewState)
        {
            LosFormatter formatter = new LosFormatter();
            StringWriter writer = new StringWriter();
            formatter.Serialize(writer, viewState);
            string viewStateString = writer.ToString();
            byte[] bytes = Convert.FromBase64String(viewStateString);
            bytes = ViewStateCompressor.CompressViewState(bytes);
            ScriptManager.RegisterHiddenField(this, &amp;quot;__VSTATE&amp;quot;, Convert.ToBase64String(bytes));
        }&lt;/pre&gt;
&lt;p&gt;I tried some workarounds in above code. &lt;br /&gt;WORKAROUND 1:&lt;/p&gt;
&lt;p&gt;In the LoadPageStateFromPersistenceMedium() method, after 1st statement i.e. string viewState = Request.Form[&amp;quot;__VSTATE&amp;quot;]; I wrote following code:&lt;/p&gt;&lt;pre class="c-sharp" name="code"&gt; if (viewState.IsNotNullOrNotEmpty(true))
      Session[&amp;quot;VSTATE&amp;quot;] = viewState;
else
      viewState = Session[&amp;quot;VSTATE&amp;quot;].ConvertToString();&lt;/pre&gt;
&lt;p&gt;So that, I can always make sure that, if viewstate is empty then take it from session which i have already saved. But this approch didn&amp;#39;t work.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;WORKAROUND 2:&lt;br /&gt;This time I tried to avoid save viewstate in hiddenfields, instead i tried to save viewstate in sessions. For this I made following chnages in above 2 mehods. Commented original code, and written new code just below commented code.&lt;/p&gt;&lt;pre class="c-sharp" name="code"&gt;        protected override object LoadPageStateFromPersistenceMedium()
        {
            //string viewState = Request.Form[&amp;quot;__VSTATE&amp;quot;];            
            //byte[] bytes = Convert.FromBase64String(viewState);
            byte[] bytes = Convert.FromBase64String(Session[&amp;quot;VSTATE&amp;quot;].ConvertToString());
            bytes = ViewStateCompressor.DecompressViewState(bytes);
            LosFormatter formatter = new LosFormatter();
            return formatter.Deserialize(Convert.ToBase64String(bytes));
        }


        protected override void SavePageStateToPersistenceMedium(object viewState)
        {
            LosFormatter formatter = new LosFormatter();
            StringWriter writer = new StringWriter();
            formatter.Serialize(writer, viewState);
            string viewStateString = writer.ToString();
            byte[] bytes = Convert.FromBase64String(viewStateString);
            bytes = ViewStateCompressor.CompressViewState(bytes);
            //ScriptManager.RegisterHiddenField(this, &amp;quot;__VSTATE&amp;quot;, Convert.ToBase64String(bytes));
            Session[&amp;quot;VSTATE&amp;quot;] = Convert.ToBase64String(bytes);

        }&lt;/pre&gt;
&lt;p&gt;But this approch also failed. Both workaround gives me following error.&lt;/p&gt;
&lt;p&gt;Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Invalid postback or callback argument.&amp;nbsp; Event validation is enabled using &amp;lt;pages enableEventValidation=&amp;quot;true&amp;quot;/&amp;gt; in configuration or &amp;lt;%@ Page EnableEventValidation=&amp;quot;true&amp;quot; %&amp;gt; in a page.&amp;nbsp; For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.&amp;nbsp; If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Please help, as my application has some scenarios where user needs to hit escape in the textboxes. If user hits it twice then I am dead. :(&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;-&lt;br /&gt;Harshal&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>