AJAX ScriptManager in UserControl(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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UserControl 中的 AJAX ScriptManager
基础教程推荐
- c# Math.Sqrt 实现 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- rabbitmq 的 REST API 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何激活MC67中的红灯 2022-01-01