我们使用asp.net网络表单来开发Outlook Web加载项。
当在更新面板中发生回发时,外接程序中出现问题,将引发一些客户端错误,这将使外接程序出现故障。这个问题是断断续续的,我们从未找到解决方案。
其中一个错误是这样的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)
我设法将加载项简化为最简单的形式,其中仅存在office.js和scriptmanager。可以看到,如果单击该按钮,则会发生回发,并且有可能引发错误:
<!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>
有趣的是,这只会在前景环境中发生。如果在Outlook之外使用相同的结构,则不会有错误。似乎scripmanage注入的Javascript与office.js或Outlook环境或两者都有冲突。但是我无法真正找到答案/解决方案。
这是我的示例代码:
<div class="loader" show.bind="isLoading" role="alert" aria-label="Loading"></div>
我在SO上只发现了一个类似的问题,但这并没有真正的帮助:
Outlook add-in,Cannot read property 'BeginRequestEventArgs' of undefined