ASP.NET Webform scriptmanager compatibility issue with Office outlook web add-in

雨燕双飞 提交于 2021-02-11 18:19:12

问题


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.

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

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)

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.

Here is my sample code:

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

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

Outlook add-in, Cannot read property 'BeginRequestEventArgs' of undefined


回答1:


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>

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.



来源:https://stackoverflow.com/questions/59985373/asp-net-webform-scriptmanager-compatibility-issue-with-office-outlook-web-add-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!