UserControl 中的 AJAX ScriptManager

AJAX ScriptManager in UserControl(UserControl 中的 AJAX ScriptManager)
本文介绍了UserControl 中的 AJAX ScriptManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 UpdatePanel 的 UserControl,其中包含一些其他控件.UserControl 将用于一些已经有 ScriptManager 的页面和其他没有 ScriptManager 的页面.如果不存在,我希望 UserControl 自动带上自己的 ScriptManager.

I have a UserControl that contains an UpdatePanel which wraps some other controls. The UserControl will be used on some pages that already have a ScriptManager and other pages that do not have a ScriptManager. I'd like the UserControl to automatically bring its own ScriptManager if one does not exist.

我已经尝试过 ScriptManager.GetCurrent,如果它返回 null,我将创建自己的 ScriptManager 并将其插入到表单中,但我无法在 UserControl 的生命周期中找到足够早的位置来运行此代码.我不断收到错误消息ID 为 'uPnlContentList' 的控件需要页面上的 ScriptManager.ScriptManager 必须出现在任何需要它的控件之前."每次我尝试加载页面.我尝试运行我的代码的地方是 OnInit、CreateChildControls 和 PageLoad,它们永远不会被调用,因为它在到达它们之前就死了.

I have tried ScriptManager.GetCurrent and if it returns null i create my own ScriptManager and insert it into the Form but I can't find a place early enough in the UserControl's lifecycle to run this code. I keep getting the error "The control with ID 'uPnlContentList' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it." every time i try loading the page. The places i've tried running my code are OnInit, CreateChildControls and PageLoad and they never get called because it dies before reaching them.

我应该把这张支票放在哪里?

Where should I put this check?

推荐答案

我讨厌从另一个方向来,但是您使用的是母版页吗?如果是这样,您是否考虑过在其上放置一个 ScriptManager 并完成它?

I hate to come at this in another direction, but are you using a master page? And if so, have you considered placing a single ScriptManager on it and being done with it?

这篇关于UserControl 中的 AJAX ScriptManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)