views:

407

answers:

2

Why can't we write a JavaScript code using Response.Write(".....") to serve the same purpose as RegisterStartupScript()?

A: 

RegisterStartupScript() will place the HTML in the correct place in your HTML (usually at the end, before the </body> tag.

Philippe Leybaert
A: 

RegisterStartupScript() will correctly wireup you script when it will be loaded from UpdatePanel. By default, code in UpdatePanel update is not treated as script - this should be done manually or by using RegisterStartupScript().

Ivan Suhinin
But what will happen if I use ICallback... -like interfaces to achieve the same goal as UpdatePanel?What would be the role of RegisterStartupScript() then?
Looks like it will be same as Response.Write("...") then. I've disassembled this method in Resharper and seems like it does nothing but registers script for UpdatePanel and generates correct <script> tags. If you will not use UpdatePanel you'll not get any actual benefit.
Ivan Suhinin