("asp.net")::如何通过(Page.ClientScript.)调用两个javascript函数 [英] ("asp.net")::how can call two javascript function by ( Page.ClientScript.)

查看:109
本文介绍了("asp.net")::如何通过(Page.ClientScript.)调用两个javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Page.ClientScript调用两个javascript函数.

但是当我使用

i need call two javascript function by use Page.ClientScript.

but when i use

Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", "onload()", true);


我不能在同一页面上使用此agin

此代码示例



i can''t use this agin in same page

example this code


Page.ClientScript.RegisterStartupScript(this.GetType(), " onload", "pro(''150'')", true);
for (int i = 1 ; i<=4;i++)
Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", "onload()", true);


-------------------------------------
只是第一个Page.ClientScript execut
但第二个否:(


-------------------------------------
just first Page.ClientScript execut
but second no :(

推荐答案

http://msdn.microsoft.com/en-us/library/z9h4dk8y.aspx [ ^ ]
http://forums.asp.net/t/1685244.aspx/1?Page+Client+Script+Overwrite[^]

http://msdn.microsoft.com/en-us/library/z9h4dk8y.aspx[^]


RegisterStartupScript中的第二个参数是KEY.因此,如果脚本已经使用该键添加到页面,则不会再次添加.

因此,如果要再次执行脚本,请更改密钥.

使用IsStartupScriptRegistered,您可以检查该密钥是否已在页面上注册

The second parameter in RegisterStartupScript is KEY. So if the script is already added to the page with that key, it will not add it again.

So change the key If you want to execute the script again.

Using IsStartupScriptRegistered you can check if that key already registered on the page

Page.ClientScript.RegisterStartupScript(this.GetType(), "pro", "pro('150')", true);
for (int i = 1 ; i<=4;i++)
Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", "onload()", true);


ipt(this.GetType(),"onload","onload()",true);


ipt(this.GetType(), "onload", "onload()", true);


当然,您要做的就是尝试覆盖旧的注册方法. RegisterStartupScript在onload方法中注册要运行的代码,第三个参数指定此代码.它不会在代码行上添加to事件.相反,您需要一次全部注册.做类似的事情:

Well of course - what you''ve done is try to overwrite the old registered method. RegisterStartupScript registers code in the onload method to run, the third parameter specifies this code. It does not add on lines of code the to event. Instead you need to register it all at once. Do something like:

string OnLoadScript = "onload(); ";
//Remember to put end line characters after statements or the resulting JavaScript code would be invalid e.g. 'onload()pro('150')' instead of valid: 'onload(); pro('150');'
OnLoadScript += "pro('150'); "
Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", OnLoadScript, true);



希望这会有所帮助,

埃德:)



Hope this helps,

Ed :)


这篇关于("asp.net")::如何通过(Page.ClientScript.)调用两个javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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