重复的脚本管理器
我正在开发 ASP.Net Webforms 应用程序,并且遇到了一个独特的问题。 MasterPage 上有一个用于更新面板的脚本管理器,以及调用母版页的子页面中的脚本管理器。我确信您会注意到这会导致抛出异常并使网络应用程序崩溃。
我尝试以编程方式从代码中排除 scriptmanager + 更新面板,如下所示:
<% If Not (Result.RawURL.Contains("ExcludedPageDirectory") Then %>
<!-- all that code goes here -->
<% End If%>
但是我认为源代码中脚本管理器标记的存在导致了错误。我将如何以编程方式处理这个问题?
I'm working on an ASP.Net webforms app, and I've run into a unique issue. There is a script manager for an update panel on the MasterPage, as well as a script manager in a sub-page calling the master page. This as i'm sure you will note cause an exception to be thrown and crash the webapp.
I've tried programatically excluding the scriptmanager + update panel from the code as follows:
<% If Not (Result.RawURL.Contains("ExcludedPageDirectory") Then %>
<!-- all that code goes here -->
<% End If%>
However I think just the presence of the script manager tag in the source is causing the error. How would I programatically handle this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一页在其层次结构中只能包含一个 ScriptManager 控件。要在父页面已有 ScriptManager 控件时为嵌套页面、用户控件或组件注册服务和脚本,请使用 ScriptManagerProxy 控件(来源:MSDN)
A page can contain only one ScriptManager control in its hierarchy. To register services and scripts for nested pages, user controls, or components when the parent page already has a ScriptManager control, use the ScriptManagerProxy control (Source: MSDN)
如果母版页中有脚本管理器,则不需要在页面中再次使用脚本管理器。
删除它并尝试
You don't require a script manager again in the page if you have it in the master page.
Remove it and try
我最终复制了母版页并省略了更新面板/脚本管理器代码。这似乎是针对给定情况的最优雅的解决方案。但是,我认为 ScriptManagerProxy 答案提供了如果无法复制母版页的最佳解决方案。
I ended up duplicating the master page and left out the update panel/scriptmanager code. This seems to have been the most elegant solution for the given situation. However I feel that the ScriptManagerProxy answer held the best possible solution had the duplication of the masterpage not been possible.