locked
How Do I Compress The ViewState and Use AJAX? RRS feed

  • Question

  • User-939035612 posted

    I just copied this class https://www.sitepoint.com/aspnet-performance-tips/ for compressing my view state, but when I run the page none of my AJAX works. I get Javascript console errors like this one:

    MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1 Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: The serialized data is invalid.
        at Function.Error.create (https://example.com/bundles/MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1:4457)
        at Sys.WebForms.PageRequestManager._createPageRequestManagerServerError (https://example.com/bundles/MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1:118177)
        at Sys.WebForms.PageRequestManager._parseDelta (https://example.com/bundles/MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1:135899)
        at Sys.WebForms.PageRequestManager._onFormSubmitCompleted (https://example.com/bundles/MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1:131983)
        at Array.<anonymous> (https://example.com/bundles/MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1:2148)
        at https://example.com/bundles/MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1:50368
        at Sys.Net.WebRequest.completed (https://example.com/bundles/MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1:86971)
        at XMLHttpRequest._onReadyStateChange (https://example.com/bundles/MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1:81635)

    Monday, May 4, 2020 1:28 AM

All replies

  • User-939035612 posted

    I take it from the lack of responses that it is not possible to both use a compressed view state and AJAX

    Tuesday, May 5, 2020 11:14 PM
  • User-1330468790 posted

    Hi CopBlaster,

     

    I just copied this class https://www.sitepoint.com/aspnet-performance-tips/ for compressing my view state, but when I run the page none of my AJAX works. I get Javascript console errors like this one:

    Could you please confirm that what you used is the class "CompressedViewStatePage" which should be the base page to be extended to compress the view state?

     

    You said

    "I take it from the lack of responses that it is not possible to both use a compressed view state and AJAX".

    However, I think it is possible to use both since Ajax does not clash with compressed view state. I think the problem is located in the below piece of codes.

    protected override void SavePageStateToPersistenceMedium(object state)  
    
    {  
    
        LosFormatter lf = new LosFormatter();  
    
        StringWriter sw = new StringWriter();  
    
        lf.Serialize(sw, state);  
    
        byte[] b = Convert.FromBase64String(sw.ToString());  
    
        ClientScript.RegisterHiddenField("__VSTATE",  
    
        Convert.ToBase64String(Compress(b)));  
    
    }  

    If you are using Ajax, the "ScriptManager" would be the choice since it is designed to manage ASP.NET Ajax script libraries and script files, partial-page rendering, and client proxy class generation for Web and application services.

     

    I find another example about how to compressed view state and you could refer to how it makes the compressed view state working with ajax.

    COMPRESSING VIEWSTATE IN ASP.NET USING AJAX

     

    Hope this can help you.

    Best regards,

    Sean

    Wednesday, May 6, 2020 2:24 AM