0

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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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().

2 Comments

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.