在某些页面上禁用 ScriptManager
我的母版页上有一个脚本管理器。 我需要从一两个内容页面中删除 webresourse.axd,因为它会导致页面上的其他 javascript 出现问题
如何禁用这些页面上的脚本管理器?
ScriptManager 对象似乎没有任何看起来可以完成这项工作的属性,
这可能吗?
I have a script manager on my Master page. There are one or 2 content pages that I need to remove the webresourse.axd from, as it is causing issues with other javascript on the page
How can I disable the script manager on these pages?
The ScriptManager object doesnt appear to have any properties that would seem like they would do the job
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将您的 移动到自定义控件,例如 MyScriptManager.ascx - .ascx 文件中的唯一代码将是 ScriptManager 标记 - 然后您可以设置 Visible< /strong> 自定义控件上的属性来控制是否呈现 ScriptManager。
您甚至可以向 MasterPage 添加一个属性,您可以在内容页面中使用该属性来显示/隐藏 ScriptManager:
由于大多数页面都需要 ScriptManager,因此将其默认为 true 可能是一个主意 - 我认为您可以在母版页的 Page_Init 方法的构造函数中执行此操作:
然后,如果您在内容页中设置了 MasterType:
您只需在内容页的 Page_Load 中执行类似的操作:
Move your <asp:ScriptManager /> to a custom control e.g. MyScriptManager.ascx - the only code in the .ascx file will be the ScriptManager tag - then you can set the Visible property on your custom control to control whether the ScriptManager gets rendered.
You could maybe even add a Property to your MasterPage which you could use in your content pages to show / hide the ScriptManager:
As most of your pages require the ScriptManager, it might be an idea to make it default to true - I think you can do this in your Master Page's constructor of Page_Init method:
Then, if you've set the MasterType in your content pages:
You just need to do something like this in content page's Page_Load:
您还可以将脚本管理器放入 ContentPlaceHolder 中,
并在要删除它的页面上,使用 asp:Content 标记指向它,它将从页面中删除它:
You could also put the script manager into a ContentPlaceHolder,
and on the pages you want to remove it , have a asp:Content tag point at it, and it will remove it from the page:
对于最终到达这里但仍然无法使其与 UserControl 一起使用的任何人...
如果您使用的是 .Net 4.0,则可以使用新的 AjaxFrameworkMode 属性并将其设置为“禁用”。
ScriptManager.AjaxFrameworkMode 属性
希望有帮助有人!
For anyone who ends up here and still can't get it to work with a UserControl...
If you are using .Net 4.0 you can use the new AjaxFrameworkMode property and set it to Disabled.
ScriptManager.AjaxFrameworkMode Property
Hope that helps someone!
我会使用嵌套母版页。 一个基础母版,其中包含您的标记以及脚本管理器所在位置的额外内容占位符。 然后是嵌套母版的两个版本,一种带有脚本管理器,一种没有。 并且您的页面使用适当的嵌套母版页。
我将留在下面的文本中,以便注释有意义,但这不起作用...
这样怎么样:
- 在您的 webconfig 中放置一个应用程序设置,其中包含您不希望有脚本管理器的 URI 列表.
- 在主服务器的 page_init 事件处理程序中,获取该集合并测试当前页面请求是否在列表中。 如果是这样,请从 master 的控件集合中删除 scriptmanager。
即,在母版页代码后面:
注意:您正在做的事情存在很多危险。 如果您的母版页有任何更新面板,或者您要删除管理器的任何页面有它们,它们就会崩溃。 您可以在 masters init 中循环遍历 master 和页面的控制集合,并检查是否有任何更新面板。 不过,我不确定如果你找到它们你会做什么。 删除它们可能会删除其中的任何内容。 最好的情况是,您可以 1) 如果找到更新面板,则不删除脚本管理器,或者 2) 自定义错误。
I would use nested master pages. A base master that has your markup with an extra content place holder where the script manager would be. Then two versions of the nested master, one with a script manager and one without. And your pages use the appropriate nested master page.
I'm leaving in the text below so the comments make sense, but this doesn't work...
How about this:
-Put an appsetting in your webconfig with a list of URI's that you don't want to have a script manager.
-In the page_init event handler of the master, get that collection and test to see if the current page request is in the list. If so, remove the scriptmanager from the controls collection of the master.
ie, in the master page code behind:
Note: There is a lot of danger in what you're doing. If your master page has any update panels, or any of the pages you are removing the manager on have them, they will bomb out. You could loop through the control collection of the master and the page in the masters init and check for any update panels as well. Although, I'm not sure what you would do if you found them. Removing them would likely remove any content in them. At best, you could either 1) not remove the Script Manager if an update panel is found, or 2) Customize the error.