UserControl 中的 AJAX ScriptManager [英] AJAX ScriptManager in UserControl

查看:21
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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