如果页面上不存在依赖控件,则抛出错误
好的,我正在制作 AJAXToolkit 控件的几个 JQuery 版本(我们在工具包方面遇到了问题),并且希望在页面上拥有它们所需的脚本的通用版本。
为此,我打算拥有一个 JQueryControlManager 控件,并使用它动态插入脚本,最好仅插入页面上的控件所需的脚本。
有谁知道一种有效的方法:
- 如果其他 JQueryControls 确实存在,则检查页面上是否存在 ControlManager 控件
- 将每个控件添加到 ControlManager 内的集合,假设第一点的答案不返回 JQueryControlManager 实例,
或者
是否有人有有更好的解决方案的建议吗?
Ok, I'm making a couple of JQuery versions of the AJAXToolkit controls (we were having issues with the toolkit), and want to have a common version of the scripts they require on the page.
To do this, I was intending to have a JQueryControlManager control, and use it to insert scripts dynamically, preferably only scripts that are needed by controls on the page.
Does anyone know of an efficient way to:
- Check a ControlManager control exists on the page if some other JQueryControls do
- Add each control to a collection within the ControlManager, assuming the answer to the first point does not return the JQueryControlManager instance
OR
Does anyone have a suggestion for a better solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
特别是对于脚本,ASP.NET 已经有一个很好的 ScriptManager 类来支持您想要执行的操作。 从您的控件中使用每个脚本的唯一键进行调用
,框架将避免重复。
ClientScriptManager
上还有其他类似的方法可能有用。如果您仍然需要创建 ControlManager 的实例,您可以只枚举
Page.Controls
集合来查找该类型的控件,即。或者您可以尝试将 ControlManager 的实例存储在
Page.Items
字典中。警告:我尚未测试此代码,因此请将其视为伪代码。
For scripts specifically, ASP.NET already has a nice ScriptManager class that supports what you're trying to do. Call
from your control with a unique key for each script and the framework will take care of avoiding duplicates. There are other similar methods on
ClientScriptManager
that may be useful.If you still need to create an instance of your ControlManager you could either just enumerate over the
Page.Controls
collection looking for a control of that type, ie.or you could try storing the instance of ControlManager in the
Page.Items
dictionary.Warning: I haven't tested this code, so treat it as pseudo-code.