0

I want to write javascript from code behind but at the end of my HTML document. With Response.Write, I can write at the beginning of the file but how can I write at the end or in an other place ?

Thanks for your help !

SeyoS
  • 661
  • 5
  • 22
  • You asking about WebForms or MVC? – Uriil Jan 26 '15 at 09:02
  • Why does it matters ? I use WebForms. – SeyoS Jan 26 '15 at 09:05
  • You should use [RegisterStartupScript](http://msdn.microsoft.com/en-us/library/asz8zsxy.aspx). – chridam Jan 26 '15 at 09:06
  • Webforms... *shudders* – mbx-mbx Jan 26 '15 at 09:07
  • If you use Response.Write it would probably break the entire layout so your question possible duplicated of [Here](http://stackoverflow.com/questions/2574131/appending-javascript-code-piece-to-the-end-of-the-body-tag) or [Here](http://stackoverflow.com/questions/2261385/neatest-way-of-adding-javascript-to-a-page-footer-in-asp-net) – Aria Jan 26 '15 at 09:21

1 Answers1

1

Write your JS function at the bottom of the HTML document, then just call it in the page load event in code behind file with

ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:someFunction();", true);
Kieran Quinn
  • 1,085
  • 2
  • 22
  • 49