ASP.NET Webform 脚本管理器与 Office Outlook Web 加载项的兼容性问题 [英] ASP.NET Webform scriptmanager compatibility issue with Office outlook web add-in

查看:82
本文介绍了ASP.NET Webform 脚本管理器与 Office Outlook Web 加载项的兼容性问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用 asp.net 网络表单来开发我们的 Outlook 网络插件.

We use asp.net webform to develop our outlook web add-in.

当在更新面板内发生回发时,加载项中存在问题,将引发一些客户端错误,这会使加载项出现故障.此问题非常间歇性,我们从未找到解决方案.

There has been an issue in the add-in when a postback occurs inside an updatepanel, some client side errors will be thrown and it will make the add-in malfuntions. This issue is quite intermittent and we never found a solution.

其中一个错误是这样的 h is not a constructor

One of the error is like this h is not a constructor

我已设法将加载项精简为最简单的形式,其中仅存在 office.js 和脚本管理器.可以观察到,如果点击按钮,会发生回发,并且有一定几率抛出错误:

I have managed to strip down the add-in to its most simple form possible, where only the office.js and the scriptmanager are present. It can be observed that if the button is hit, a postback occurs and there is some chance that an error is thrown:

Uncaught TypeError: Cannot read property 'PageRequestManager' of undefined
    at Sys._Application.dispose (VM7863 ScriptResource.axd:5)
    at Sys._Application._unloadHandler (VM7863 ScriptResource.axd:5)
    at VM7863 ScriptResource.axd:5
    at b (VM7863 ScriptResource.axd:5)

有趣的是,这只会发生在 Outlook 上下文中.在outlook之外使用相同的结构时,不会出现错误.似乎 Scripmanage 注入的 Javascript 与 office.js 或 Outlook 环境或两者都有冲突.但我无法真正得到答案/解决方案.

Interestingly this will only happen in the outlook context. When the same structure is used outside of outlook, there will be no error. It seems like the scripmanage's injected Javascript is conflicting with office.js or the outlook enviroment or both. But I cannot really get the answer/solution.

这是我的示例代码:

<!DOCTYPE html>
<html>
<head runat="server">
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <!-- For the JavaScript APIs for Office, go to https://aka.ms/officejs-overview to learn more. -->
    <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
</head>
<body>
    <h4>Sample APP to replicate the scripte manager issue</h4>
    <form id="form" runat="server">
        <asp:scriptmanager id="ScriptManager" runat="server" scriptmode="Release" asyncpostbacktimeout="300" />
        <asp:button id="button" runat="server" text="Click Me!" />
    </form>
    <script>
        Office.initialize = function () { };
        var prm = Sys.WebForms.PageRequestManager.getInstance();
    </script>
</body>
</html>

我只在 SO 上发现了一个类似的问题,但它并没有真正帮助:

I have only found one similar issue on SO but it does not really help:

Outlook 加载项,无法读取属性BeginRequestEventArgs"未定义的

推荐答案

当前的解决方法是将 office.js 引用放在 scriptmanager 控件之后.本质上它的作用是确保 scriptmanager 生成的脚本将在 office.js 之前加载/执行.

The current work around is to put the office.js reference after the scriptmanager control. Essentially what it does is to make sure that the scripts generated by scriptmanager will be loaded/executed before office.js.

<asp:scriptmanager id="ScriptManager" runat="server" scriptmode="Release" onasyncpostbackerror="ScriptManager_AsyncPostBackError" asyncpostbacktimeout="300" />
<!-- For the JavaScript APIs for Office, go to https://aka.ms/officejs-overview to learn more. -->
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>

查看office.js的源码.似乎它有一些与 ajax 内容(Sys、MicrosoftAjax.js 等)相关的引用.这可能是问题所在.

Have a look at the source of the office.js. Seems like it has some referece relating to the ajax stuff (Sys, MicrosoftAjax.js etc) That might be the problem.

这篇关于ASP.NET Webform 脚本管理器与 Office Outlook Web 加载项的兼容性问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆