Page view counter

Ajax Beta 1, UpdatePanel and Viewstate issue

Last post 01-22-2008 4:45 PM by ModMa. 13 replies.

Sort Posts:

  • Ajax Beta 1, UpdatePanel and Viewstate issue

    10-26-2006, 3:23 AM
    • Loading...
    • colt45
    • Joined on 01-03-2006, 10:01 PM
    • Milan, ITALY
    • Posts 3
    • Points 15

    Hi all,

    I have found what could be a possible bug in the beta 1 regarding the use of the UpdatePanel with postback events.

    If we use the update panel and inside it there is a control like a linkbutton that raise a postback, then the event is generated on the server and everything is going on correctly.

    In my scenario I have a base page class that overrides the Viewstate load and save methods to compress and decompress it.A simply code that work fine without ajax and with the atlas ctp.(the code put the compressed viewstate content in another hidden field and let the original __VIEWSTATE empty).

    With beta1 I've found that with a viewstate compression, this cause the postback events not raised with the right postback value.This happens for example when we click for the second time to the link button, when the viewstate has to be regenerated from the previous click.

    I don't know what happens but I think that something has changed in the way the beta1 and UpdatePanel look at the viewstate.

    Anyone has had the same issue ?

    Luca
  • Re: Ajax Beta 1, UpdatePanel and Viewstate issue

    11-09-2006, 4:02 PM
    • Loading...
    • Rossoneri
    • Joined on 11-09-2006, 8:57 PM
    • O-H I-O
    • Posts 433
    • Points 2,079

    I just had this problem occur to me this afternoon. Upgraded to the new beta 2 from Atlas and the controls inside my update panels that stored values in ViewState started behaving funny. I too was inheriting from a base class that compressed and cached ViewState. As soon as I took this out and went back to System.Web.UI.Page, the controls worked fine again. This really sucks as we were able to trim so much bloat out of the page by compressing the ViewState. It would be wonderful if MS would consider this.

     

    Forza Milan! 

  • Re: Ajax Beta 1, UpdatePanel and Viewstate issue

    11-09-2006, 4:56 PM
    • Loading...
    • kashif
    • Joined on 06-11-2002, 1:34 PM
    • Posts 547
    • Points 2,738
    • AspNetTeam
      Moderator

    Colt45, to get his scenario working, you would need to explicitly register the hidden field that stores the compressed value of viewstate with ScriptManager, so that the framework would know that it needs to send the updated value for this to the client during an async post-back. I am guessing that you currently use Page.ClientScript.RegisterHiddenField(...) to render your compressed view state. Change this to ScriptManager.RegisterHiddenField(...)

     This should fix your issue.

     Hope that helps!

  • Re: Ajax Beta 1, UpdatePanel and Viewstate issue

    11-10-2006, 3:45 AM
    • Loading...
    • colt45
    • Joined on 01-03-2006, 10:01 PM
    • Milan, ITALY
    • Posts 3
    • Points 15

    Thank you very much, kashif

    It works well now...

    Luca
  • Re: Ajax Beta 1, UpdatePanel and Viewstate issue

    11-10-2006, 5:10 AM
    • Loading...
    • colt45
    • Joined on 01-03-2006, 10:01 PM
    • Milan, ITALY
    • Posts 3
    • Points 15

    Sorry....my previous post was wrong...it doesn't work!

    I' ve used the ScriptManager.RegisterHiddenField as you suggest but nothing changed.

    I need a solution because the viewstate compression is a usefull feature that I don't want to give up, as like as I don't with Ajax...

     

    Luca
  • Re: Ajax Beta 1, UpdatePanel and Viewstate issue

    11-15-2006, 1:19 PM
    • Loading...
    • Rossoneri
    • Joined on 11-09-2006, 8:57 PM
    • O-H I-O
    • Posts 433
    • Points 2,079

    It did not work for me either.

    Most of the problems I see are occuring in GridViews with paging and/or sorting. For example, I have a sorting routine that sorts ASC the first time the header is clicked and then DESC if it is clicked again. The value is stored in ViewState. The first time I click the header, the columns sorts ASC as expected. At this point, "ASC" is stored in ViewState so that when the header is clicked again, I can check this value and then sort by the reverse ("DESC"). However, the grid sorts ASC with every click because the new value is not persisting.

    Paging also causes problems. The page data will refresh on the screen correctly between pages 1, 2, 3 etc. However, if I click a button in the 3rd row on the 3rd page that is supposed to update that customer record, it will actually retrieve the customer record that is on the 3rd row of the 1st page. In other words, Ajax always thinks the grid is on the 1st page even though the data on the screen reflects the 3rd page.

    If I turn off compressing/caching ViewState, it works fine.
    If I leave compression/caching enabled, but turn of Ajax, it works fine.
    But together, the marriage fails.


     

  • Re: Ajax Beta 1, UpdatePanel and Viewstate issue : resolved

    11-24-2006, 7:05 AM
    • Loading...
    • shunzimm
    • Joined on 11-17-2006, 4:30 AM
    • china
    • Posts 9
    • Points 23

        protected override void SavePageStateToPersistenceMedium(Object pViewState)
        {
            Pair pair1;
            System.Web.UI.PageStatePersister pageStatePersister1 = this.PageStatePersister;
            Object ViewState;
            if (pViewState is Pair)
            {
                pair1 = ((Pair)pViewState);
                pageStatePersister1.ControlState = pair1.First;
                ViewState = pair1.Second;
            }
            else
            {
                ViewState = pViewState;
            }

            LosFormatter mFormat = new LosFormatter();
            StringWriter mWriter = new StringWriter();

            mFormat.Serialize(mWriter, ViewState);
            String mViewStateStr = mWriter.ToString();

            byte[] pBytes = System.Convert.FromBase64String(mViewStateStr);

            pBytes = Compress(pBytes);

            String vStateStr = System.Convert.ToBase64String(pBytes);

            pageStatePersister1.ViewState = vStateStr;

            pageStatePersister1.Save();
        

            //ClientScript.RegisterHiddenField("__MSPVSTATE", vStateStr);

        }

        protected override Object LoadPageStateFromPersistenceMedium()
        {
            System.Web.UI.PageStatePersister pageStatePersister1 = this.PageStatePersister;
            //try
            //{
                pageStatePersister1.Load();
            //}
            //catch
            //{
            //    return null;
            //}

            String vState = pageStatePersister1.ViewState.ToString(); 

            byte[] pBytes = System.Convert.FromBase64String(vState);

            pBytes = DeCompress(pBytes);

            LosFormatter mFormat = new LosFormatter();

            Object ViewState = mFormat.Deserialize(System.Convert.ToBase64String(pBytes));

            return new Pair(pageStatePersister1.ControlState, ViewState);
        }

  • Re: Ajax Beta 1, UpdatePanel and Viewstate issue : resolved

    12-04-2006, 6:23 PM
    • Loading...
    • AGBrown
    • Joined on 05-26-2006, 9:53 PM
    • Posts 42
    • Points 136

    Using ScriptManager.RegisterHiddenField(...) works fine in Beta 2 as long as you set the first argument as an update panel. The update panel can be empty, and should have its UpdateMode set to Always. Using Fiddler you should be able to see your new viewstate hidden field change appropriately.

    Whether this is any better or worse than the code in the previous post, I don't know.

     Andy

    1    	protected override object LoadPageStateFromPersistenceMedium()
    2    	{
    3    		string viewState = Request.Form["__VSTATE"];
    4    		byte[] bytes = Convert.FromBase64String(viewState);
    5    		bytes = Compressor.Decompress(bytes);
    6    		LosFormatter formatter = new LosFormatter();
    7    		return formatter.Deserialize(Convert.ToBase64String(bytes));
    8    	}
    9    	protected override void SavePageStateToPersistenceMedium(object viewState)
    10   	{
    11   		LosFormatter formatter = new LosFormatter();
    12   		StringWriter writer = new StringWriter();
    13   		formatter.Serialize(writer, viewState);
    14   		string viewStateString = writer.ToString();
    15   		byte[] bytes = Convert.FromBase64String(viewStateString);
    16   		bytes = Compressor.Compress(bytes);
    17   		ScriptManager.RegisterHiddenField(this.updVS, "__VSTATE", Convert.ToBase64String(bytes));
    18   	}
    
     
    Filed under:
  • Re: Ajax Beta 1, UpdatePanel and Viewstate issue : resolved

    01-22-2007, 11:47 AM
    • Loading...
    • pnmcosta
    • Joined on 10-06-2006, 6:44 PM
    • Posts 61
    • Points 145

    Hi,

    I to am experiencing this problem, i'm using Ajax RC1. I would take the option to use the scriptmanager but i have 2 major problems with this solution, i have a master page that contains the scriptmanager, and i want to apply this to all my existing pages. How can i reference the scriptmanager on the master page from the base class? If at all possible?

     
    Kind regards,

    Pedro Costa
     

  • Re: Ajax Beta 1, UpdatePanel and Viewstate issue : resolved

    01-25-2007, 1:36 PM
    • Loading...
    • Rossoneri
    • Joined on 11-09-2006, 8:57 PM
    • O-H I-O
    • Posts 433
    • Points 2,079

    Use shunzimm solution above. A slightly modified version of it worked well for me. I have ScriptManager on my master page and it works fine.

  • Re: Ajax Beta 1, UpdatePanel and Viewstate issue : resolved

    10-22-2007, 4:02 PM
    • Loading...
    • stimmell
    • Joined on 12-18-2006, 7:22 PM
    • Posts 22
    • Points 4

    This might perhaps be due to changes in the ajax framework, but I've found that you do not need a update panel for ScriptManager.RegisterHiddenField() to work. I just used this as the first param and everything seems okay so far.

  • Re: Ajax Beta 1, UpdatePanel and Viewstate issue : resolved

    10-24-2007, 3:51 PM
    • Loading...
    • jtoth55
    • Joined on 03-22-2005, 12:17 AM
    • Maryland
    • Posts 142
    • Points 448

    Thanks for this post, fixed my issue too with using scriptmanager. One question I have is does it buy anything to have this viewstate compression code on top of IIS 6 HTTP Compression or does http compression make this code obselete?

    Justin Toth
    http://tothsolutions.com
    http://tothsolutions.com/blog
  • Re: Ajax Beta 1, UpdatePanel and Viewstate issue : resolved

    11-09-2007, 12:50 PM
    • Loading...
    • Mark Smith
    • Joined on 11-09-2007, 5:42 PM
    • Posts 1
    • Points 2

    I've been trying to use the compression code in my application and I'm finding that it's causing problems with a few gridviews that I'm using.  What's happening is that the 'OnRowUpdating' and the 'OnRowCancelingEdit' events are not being fired.  I have an 'update' and 'cancel' LinkButton inside an 'EditItemTemplate' tag in a 'TemplateField'.  The 'OnRowEditing' and the 'OnRowDeleting' events are being fired, but not the other two.  Do you have any idea why this might be happening?  Any help would be greatly appreciated.

  • Re: Ajax Beta 1, UpdatePanel and Viewstate issue

    01-22-2008, 4:45 PM
    • Loading...
    • ModMa
    • Joined on 01-22-2008, 4:27 PM
    • Posts 3
    • Points 6

    you can found a experimental version of a ViewState Compressor compatible with MS Ajax in this url:

    http://www.codeproject.com/KB/aspnet/ViewStateSerializer.aspx

    Greetings 

Page 1 of 1 (14 items)