4

Strange behavior appears when using Update-panel on web part in Share-point 2013.

Everything works fine but after several(2-3 minutes), any action in page cause Full page load.

In FF and Chrome post-back leads to full page refresh after small idle between requests (around 2 minutes).

Example: we have a page with Tree-view and button inside Update-panel. We open this page and click the button or Tree-view node -> update-panel refreshes its content without page reload. If we will wait more than 2 minutes and click the button or Tree-view node again, page will reload.

  • Hi. I got the same problem today. Have you got any solution or workaround? – Kaushal Khamar Sep 3 '15 at 11:23
0

I have solver this anonymous problem by adding this javascript. I have found that after some ideal time(~30sec) for each request it page goes for authenticate user. and if user is not authentication then it reload the whole page and re authenticate user that's why page is reload.

Add this java script code in your page which will solve your problem.

<script type="text/javascript">

    var isNtlmActive = false;
    var updatePannelsToUpdate = [];
    var eventTarget = '';
    var eventArgument = '';
    var causesValidation = false;
    var validationGroup = '';
    var requestBody = '';

    function initializeRequestHandler(sender, args) {
        var onSuccess = function () {
            //At this point the NTLM connection is re-established 

            var pageRequestManagerInstance;
            isNtlmActive = true;

            pageRequestManagerInstance = Sys.WebForms.PageRequestManager.getInstance();

            // re-issuing the 'original' request
            pageRequestManagerInstance.beginAsyncPostBack(updatePannelsToUpdate, eventTarget, eventArgument, causesValidation, validationGroup);
        };

        var onError = function () {
            // do something here if error occurred
        }

        if (!isNtlmActive) {
            // capturing and preserving the body as well as some other meta data about the original request
            requestBody = args.get_request().get_body();
            updatePannelsToUpdate = sender._postBackSettings.panelsToUpdate;
            eventTarget = sender._postBackSettings.asyncTarget;
            eventArgument = '';
            causesValidation = false;
            validationGroup = '';

            // NOTE: the variable '_spFormOnSubmitCalled' is a global variable that gets injected by the logic iplemented in the 'init.js' file.  
            // Based on our observation of the logic in 'init.js' the varialbe '_spFormOnSubmitCalled' is set to true when HTML form's

            // 'onsubmit'  function is called and it is never set back to false (after we cancel the postback)
            // As the result, any subsequent attempts to submit the form do not work.
            // Thus, we excplicetely set the value back to false before we cancel the original post back request.
            //
            //'init.js'is autoatically referenced by SharePoint and included on to the 'master' page.
            // The HTML form as well as the functionality to handle submit is also provided by SharePoint.
            if (typeof _spFormOnSubmitCalled === "boolean") {
                _spFormOnSubmitCalled = false;
            }
            args.set_cancel(true);

            callServerSideServiceToReviveNtlmSession(onSuccess, onError);
        }
        else {
            // resetting the body of the request with the value captured from the original request
            args.get_request().set_body(requestBody);

            isNtlmActive = false;
            updatePannelsToUpdate = [];
            eventTarget = '';
            eventArgument = '';
            causesValidation = false;
            validationGroup = '';
        }
    }

    function getCurrentSiteCollectionUrl() {
        var url;

        url = window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl;

        return url;
    }

    function callServerSideServiceToReviveNtlmSession(successHandler, errorHandler) {
        var siteCollectionUrl;
        var testServiceUrl;
        var spRequestExecutor;
        var request;

        siteCollectionUrl = getCurrentSiteCollectionUrl();
        testServiceUrl = siteCollectionUrl + "/_api/web/title";

        spRequestExecutor = new SP.RequestExecutor(siteCollectionUrl);
        request = {
            url: testServiceUrl,
            method: "GET",
            headers: { "Accept": "application/json; odata=verbose" },
            success: successHandler,
            error: errorHandler
        };
        spRequestExecutor.executeAsync(request);
    }

    try {
        $(document).ready(function () {
            try {
                var pageRequestManagerInstance = null;

                //Note: Sys.WebForms.PageRequestManager gets injected into your page the minute you use ScriptManager (and UpdatePanel)
                pageRequestManagerInstance = Sys.WebForms.PageRequestManager.getInstance();

                pageRequestManagerInstance.add_initializeRequest(initializeRequestHandler);
            }
            catch (ex) {
                //alert('INNER EXCEPTION: document ready - ' + ex.message);
            }
        });
    }
    catch (ex) {
        //alert('EXCEPTION: document ready - ' + ex.message);
    }
</script>

Mark as answer if this answer found helpful...

Thanks..!!

-1

The ASP.NET AJAX UpdatePanel control must change the page’s postback behavior to enable support for asynchronous post backs and partial rendering. However, in a SharePoint application, these modifications cause a JavaScript error. This is because SharePoint attempts to make a similar change. The SafeScriptManager control corrects the JavaScript problem.

Solution . i have refereed msdn . i m shareing with u guys .

In Visual Studio, add a reference to Microsoft.Practices.SPG.AJAXSupport.dll. Add a SafeScriptManager control to your page and set the EnableUpdatePanelSupport flag to true. This changes the postback script that is needed for the UpdatePanel control to work in a SharePoint environment. The following code demonstrates how to add a SafeScriptManager control to a page.

Link : https://msdn.microsoft.com/en-us/library/ff650218.aspx

  • 1
    That guidance applies to SharePoint 2007 only. – Rob Windsor Sep 3 '15 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.