使用ASP.NET在运行时生成警报框的差异 [英] Differences in generating alert box at runtime using ASP.NET

查看:64
本文介绍了使用ASP.NET在运行时生成警报框的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





Hi,

difference b/w Response.Write("<script>alert('Hello');</script>") and this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Hello!')", true) ?





哪一个是最好的方式,为什么?











我面对面试中的这个问题



提前感谢你



我的尝试:



我试过这个.Page.ClientScript.RegisterStartupScript(this.GetType(),alert,alert('Hello!'),true )



以上脚本无法正常工作。我在我的代码中使用更新面板,如何解决此问题。 Plz帮助这个。



Which one is Best way and why?





I face this question in Interview

Thanking you in advance

What I have tried:

I tried with this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Hello!')", true)

above script is not working properly. I'm using update panel in my code, how resolve this issue. Plz help one this.

推荐答案

你无法控制response.write放置输出的位置,但registerstartupscript确保代码进入正确的位置以便在页面运行时负载。您还可以为脚本提供一个密钥,让您检查脚本是否已经由不同的代码段添加。



另一个需要注意的重要事项是实际上在那里执行javascript然后由于页面还没有发送到客户端。
You can't control where response.write places your output, but registerstartupscript ensures the code goes in the correct place to run when the page loads. You can also give the script a key that lets you check if the script has already been added by a different section of code.

Another important thing to note is that neither actually execute the javascript there and then as the page has not been sent to the client yet.


这篇关于使用ASP.NET在运行时生成警报框的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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