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


- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01