2

我在我的 SharePoint 可视化 Web 部件中使用了多个更新面板。一切正常,直到我让页面闲置一段时间。

例如,如果我更改了几个下拉菜单并让页面闲置约 5 分钟。返回页面并更改下拉菜单将导致完整的回发。

另一个例子是使用带有分页的gridview。离开第 5 页的网格视图。闲置 5 分钟,然后返回页面。例如,单击第 8 页将使 gridview 转到第 1 页。

我是使用 Updatepanels 的新手,非常感谢一些建议。

4

2 回答 2

0

我通过添加这个 javascript 来解决这个匿名问题。我发现在每个请求经过一段理想的时间(~30 秒)后,它的页面就会用于验证用户。如果用户没有进行身份验证,那么它会重新加载整个页面并重新验证用户身份,这就是重新加载页面的原因。

在您的页面中添加此 java 脚本代码,这将解决您的问题。

<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>

如果此答案有帮助,请标记为答案...

谢谢..!!

于 2015-10-23T13:10:57.070 回答
-1

在整个场中启用或禁用会话状态

在任务栏上,单击“开始”,指向“管理工具”,然后单击“SharePoint 3.0 管理中心”。

在顶部导航栏中,单击应用程序管理选项卡。

在“应用程序管理”页面的“Office SharePoint Server 共享服务”部分中,单击“配置会话状态”。

在“配置会话状态”页面的“启用会话状态”部分中,选中“启用会话状态”复选框以启用场的会话状态。

要指定会话的持续时间,请在“超时”部分中的“会话应在(分钟)之后超时”框中输入一个数字(以分钟为单位)。默认值为 60 分钟。

单击“确定”保存会话状态配置。

这个会给你更多的指导

http://technet.microsoft.com/en-us/library/cc263527.aspx

如果有任何困惑问我,

于 2013-08-27T14:00:35.500 回答