How to Add script codes before the </body> tag ASP.NET

纵然是瞬间 提交于 2019-12-02 13:23:09

问题


Heres the problem,

In Masterpage, the google analytics code were pasted before the end of body tag.

In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript and put it before the end of body tag, because this script uses the google analytics variables.

How can i achieve this?


回答1:


An inelegant but simple approach, if you're able to avoid using ClientScript, would be to just stick a literal in the page where you want your script to be rendered and put the script in there from your codebehind (i.e. myLiteral.Text = "client script";).




回答2:


Take a look at RegisterStartupScript

The script block will be placed right above the </form> tag at the end of the page.




回答3:


You could delay your script execution until after the page loads, then it won't matter where your script resides.



来源:https://stackoverflow.com/questions/1726962/how-to-add-script-codes-before-the-body-tag-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!