以编程方式阻止 ASP .NET AJAX 脚本呈现
有谁知道我可以阻止所有 .NET AJAX 脚本渲染的方法,即使页面上存在 ScriptManager 也是如此?
ScriptManager 的 Visible 属性已被覆盖并禁用,因此如果您尝试设置 Visible 属性,您将收到 NotImplementedException。
我想这样做的原因是,当不需要时,我不希望这些大块的 javascript 遍布我的页面。 ScriptManager 需要包含在母版页上,以确保只添加一个 ScriptManager,但同一个母版页必须有两个版本(一个启用了 ajax,另一个不启用),这将是愚蠢的。
编辑:我实际上正在使用 Telerik 的 RadScriptManager 和 RadAjax,以防有人知道使用这些类的方法。
Does anyone know of a way that I can stop all the .NET AJAX scripts from rendering, even if a ScriptManager exists on the page?
The ScriptManager's Visible property has been overridden and disabled so that you receive a NotImplementedException if you try to set the Visible property.
The reason I would like to do this is that I don't want these large chunks of javascript all over my pages when they are not required. The ScriptManager needs to be included on the master page to ensure that only one ScriptManager is added, but it would be stupid to to have to have two versions of the same master page - one ajax enabled and one not.
Edit: I am actually using Telerik's RadScriptManager with RadAjax, in case anyone knows a method using these classes instead.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查看 Bertrand LeRoy 的“将 ScriptManager 与其他框架结合使用”
http://weblogs.asp.net/bleroy/archive/2008/07/07/using-scriptmanager-with-other-frameworks.aspx
包含一个继承自 ScriptManager 的控件,该控件可撤消某些操作其内置脚本添加,并允许您将其替换为您喜欢的任何框架。
Check out Bertrand LeRoy's "Using ScriptManager with other frameworks"
http://weblogs.asp.net/bleroy/archive/2008/07/07/using-scriptmanager-with-other-frameworks.aspx
Contains a control that inherits from ScriptManager which undoes some of its built-in script additions and allows you to replace it with whatever framework you like.
不要将其用作母版页中的实际控件,而是创建它的实例并将其添加到页面(如果需要); 也许您的母版页上甚至有一个属性来控制它是否被包含。
Instead of using it as an actual control in the master page, create an instance of it and add it to the page if needed; perhaps even have a property on your master page that controls whether or not it gets included.
您可以检查的一个选项可能是使用 ScriptManager 的 CompositeScript 块。 这样,您可以将它们全部合并到 1 个浏览器可缓存的脚本资源调用中。 您还可以将任何其他常见脚本添加到此块中。
有一个关于它的截屏,我用过它之前,它似乎工作得很好。
An option you could check out might be to use ScriptManager's CompositeScript block. That way, you can merge them all into 1 browser-cachable script-resource call. You can also add any other common scripts into this block too.
There is a screencast about it, I've used it before and it seems to work pretty well.
我已经解决了类似的问题 - 即:以编程方式将 HoverMenuExtender 从 Ajax 控制工具包中排除 - 通过将其包装在 标签内,该标签允许设置其 Visible< /strong> 代码隐藏中的属性。 如果占位符不可见,则它不会呈现到页面上 - 包括所有子控件。 还没有尝试过使用 ScriptManager,但它也可以在这里工作。
干杯,奥利弗
I have solved a similar problem - namely: programmatically in- or excluding a HoverMenuExtender from the Ajax Control Toolkit - by wrapping it inside a <asp:PlaceHolder> tag which allows setting its Visible property in code-behind. If the placeholder is invisible, it will not be rendered onto the page - including all child controls. Haven't tried it with the ScriptManager but it could work here as well.
Cheers, Oliver