的Response.Write()和ClientScript.RegisterStartupScript()之间的区别? [英] Difference between Response.Write() and ClientScript.RegisterStartupScript()?

查看:147
本文介绍了的Response.Write()和ClientScript.RegisterStartupScript()之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是什么回复于()和ClientScript.RegisterStartupScript之间的差值()
谢谢你。

What is the difference between Response.Write() and ClientScript.RegisterStartupScript() Thank you.

推荐答案

的Response.Write 方法可以在的呈现阶段用于输出code页。在<%=%> 服务器标记是一个快捷键<%的Response.Write()%>

The Response.Write method can be used to output code during the rendering phase of the page. The <%= %> server tag is a shortcut for <%Response.Write( )%>.

如果您使用的Response.Write 从code后面,你会写入页面之前,它已经开始呈现,因此code将结束了html文件之外。 Eventhough浏览器将执行code,它不能正常工作。 DOCTYPE标签之前有得将使得浏览器忽略文档类型和渲染怪癖模式,通常打破了布局的页面。另外,作为脚本运行中存在的页面任何东西之前,在code不能访问页面中的任何元素。

If you use Response.Write from the code behind, you will write to the page before it has started rendering, so the code will end up outside the html document. Eventhough the browser will execute the code, it doesn't work properly. Having something before the doctype tag will make the browser ignore the doctype and render the page in quirks mode, which usually breaks the layout. Also, as the script runs before anything of the page exists, the code can't access any elements in the page.

ClientScript.RegisterStartupScript 的方法是动态地添加脚本到页面的preferred方式。它将在形式的末端呈现脚本,以便它不会破坏的HTML documnet,并且它可以在形式访问的元素。

The ClientScript.RegisterStartupScript method is the preferred way of adding script dynamically to the page. It will render the script at the end of the form so that it doesn't break the html documnet, and it can access the elements in the form.

另外,你给每个脚本一个身份,这意味着重复被删除。如果用户控制寄存器的脚本,并使用用户控件的多个实例,该脚本将只在一次页面渲染。

Also, you give each script an identity, which means that duplicates are removed. If a user control registers a script, and you use several instances of the user control, the script will only be rendered once in the page.

这篇关于的Response.Write()和ClientScript.RegisterStartupScript()之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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