你为什么不能UnRegisterStartupScript? [英] Why can't you UnRegisterStartupScript?

查看:181
本文介绍了你为什么不能UnRegisterStartupScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,这是一个有点怪异,你可以做。

Seems to me it is a bit wierd that you can do..

Page.ClientScript.RegisterStartupScript(this.GetType(), "KeyName", "alert('changed my mind')", true);

再后来就不能注销或者被编程渲染停止的JavaScript。

And then later on you can't unregister or stop the javascript from being rendered programatically.

为什么微软这样做呢?

我不喜欢的工作在这里..
<一href=\"http://hemant-vikram.blogspot.com/2005/11/unregister-startup-script-workaround.html\">http://hemant-vikram.blogspot.com/2005/11/unregister-startup-script-workaround.html

I don't like the work around here.. http://hemant-vikram.blogspot.com/2005/11/unregister-startup-script-workaround.html

和我不喜欢的只是重新注册它,有它什么都不做的选择。

And I don't like the option of just re-registering it and having it do nothing..

思考?

推荐答案

我以为你会想注销的脚本(已注册),一定条件下,像这样:

I assume that you'd want to "unregister" the script (which has already been registered) under some condition, like so:

Page.ClientScript.RegisterStartupScript(this.GetType(), "KeyName", "alert('changed my mind')", true);
...
if(condition)
    Page.ClientScript.UnregisterStartupScript(this.GetType(), "KeyName", "alert('changed my mind')", true);

为什么不能这只是更改为:

Why can't this simply be changed to:

if(!condition)
    Page.ClientScript.RegisterStartupScript(this.GetType(), "KeyName", "alert('changed my mind')", true);

这篇关于你为什么不能UnRegisterStartupScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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