About the author

Miron Abramson
Software Engineer,
CTO at PixeliT
and .NET addicted for long time.
Open source projects:
MbCompression - Compression library

Recent comments



The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2018

Creative Commons License

Blog Flux Directory
Technology Blogs - Blog Top Sites

Optimize your page for UpdatePanel - part II

In the previews post about Optimize your page for UpdatePanel I talked about removing white spaces from the ASPX to optimize the Update Panel callbacks because it can't be compressed as normal response, and thats due the special  format that this response is (it needs to be parse be JS in the client side).

The Update Panel response contain the new html for the specific location that needs to be update and the complete new ViewState for the whole page. So, one more thing we can to optimize the UpdatePanel is to compress the ViewState before it been sent to the client. We don't need to do it in normal response because we use (or should use) a compression module that compress all the page response and that includes the ViewState. Compress the ViewState can save you some more KB from the async response. Another option is to save the ViewState in the server (file os session), and not send it at all. To compress the ViewState we needs to override the 'LoadPageStateFromPersistenceMedium' and the 'SavePageStateToPersistenceMedium' methods that load and save the view state.

Here is the code how to compress the ViewState for the UpdatePanel response only, just copy it to your base page:

 protected override object LoadPageStateFromPersistenceMedium()
    string viewState = Request.Form["__COMPRESSEDVS"];
    if (viewState != null)
         byte[] data = Convert.FromBase64String(viewState);
         data = Utils.Decompress(data);
         LosFormatter lf = new LosFormatter();
         return lf.Deserialize(Convert.ToBase64String(data));
         return base.LoadPageStateFromPersistenceMedium();

protected override void SavePageStateToPersistenceMedium(object viewState)
    if (Utils.IsMsAjaxCallback(Request))
         LosFormatter lf = new LosFormatter();
         using (StringWriter writer = new StringWriter())
             lf.Serialize(writer, viewState);
             string viewStateString = writer.ToString();
             byte[] data = Convert.FromBase64String(viewStateString);
             data = Utils.Compress(data);
             ScriptManager.RegisterHiddenField(this, "__COMPRESSEDVS", Convert.ToBase64String(data));

 (The class 'Utils' can be download here: Utils.cs (1.15 kb))

Currently rated 4.5 by 2 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by Miron on Saturday, November 24, 2007 3:16 AM
Permalink | Comments (14) | Post RSSRSS comment feed