复制的ScriptManager的javascript [英] ScriptManager duplicates javascript

查看:223
本文介绍了复制的ScriptManager的javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可用于例如一个GridView ItemTemplate中一个用户控件,这意味着控制可能会或可能不会在页面加载的页面上。在控制是一个ItemTemplate内的情况下,我会通过popupate异步回发在GridView(通过的UpdatePanel)。

I have a usercontrol that can be used in for example a gridview itemtemplate, this means that the control might or might not be on the page at page load. In the case where the control is inside an itemtemplate i will popupate the gridview via asynchronous postbacks (via updatepanels).

,因为它控制itselfs registrers scriptblocks取决于JavaScript的。首先我用

The control itselfs registrers scriptblocks since it is depending on javascripts. First i used

Page.ClientScript.RegistrerClientScriptBlock

但是,这并不对异步回发(UpdatePanel的)工作,所以我又试图使用的相同的ScriptManager这让我回发异步后registrer网页上的脚本。大!。

But this doesn't work on asynchronous postbacks (updatepanels) so i then tried the same using ScriptManager which allows me to registrer scripts on the page after async postbacks. great!.

ScriptManager.RegisterClientScriptBlock

不过,ScriptManager的(我所知道的)不具有后的功能,看是否有剧本已经在页面上,所以我会为每一个回传生成脚本块的内容,这是ofcourse不必要的行为。

However, ScriptManager (what i know of) does not have the functionallity to see if a script already is on the page, so i will for every postback generate duplicates of the script blocks, this is ofcourse unwanted behaviour.

我没有在谷歌运行,我发现我可以调用PageRequestManager的Dispose()方法可以使用​​,这样做的工作,因为它清除脚本,然后重新添加它们(这也解决了我的问题与删除未使用的脚本从已删除的控制块)。

I did a run at Google and found that i can call the Dispose() method of the PageRequestManager can be used, this does work since it clears the scripts and then adding them again (this also solves my issue with removing unused script blocks from removed controls).

Sys.WebForms.PageRequestManager.getInstance().Dispose()

不过着,当然也因为即时通讯张贴在这里:)不利的一面。
的Dispose()方法处置母版页上的实例以及导致运行有脚本将停止异步回发(的UpdateProgress为例)后发挥作用。

However, ofcourse there is a downside since im posting here :). The Dispose() method disposes the instance on the master page as well which leads to scripts running there will stop to function after an async postback (updateprogress for example).

那么,有没有一种方法来检查,如果脚本中使用的ScriptManager或任何其他工具的页面上已经存在,将prevent我插入重复的脚本?此外,有没有一种方法来移除某些脚本块(当我在ItemTemplate中例如删除项目)。

So, is there a way to check if a script already exists on the page using ScriptManager or any other tools, that will prevent me of inserting duplicate scripts? Also, is there a way to remove certain script blocks (when i am removing an item in itemtemplate for example).

提前非常感谢。

推荐答案

如果你再注册时设置的相同类型和关键属性我认为SM将只包括其中的一个。

If you set the same type and key attributes when registering then I think the SM will include only one of these.

这篇关于复制的ScriptManager的javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆