Adding a piece of javascript code to the end of the body tag

I am looking for a way to insert a javascript code block at the end of an ASP.NET page.

Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "showVideo", sScript, true); 

is added to the body, but js codes always request some js files that don't load, or some functions below the script.

How can I add scripts that I dynamically generated in the lower body?

Thanks for your help.

+4
source share
2 answers

We use something like

  public static void GenerateJsTag(this TemplateControl page, string jsCode) { var jsLink = new HtmlGenericControl {TagName = "script", InnerHtml = jsCode }; jsLink.Attributes.Add("type", "text/javascript"); page.Controls.Add(jsLink); } 

hope this helps;)

+10
source

Adding Client Side Script Blocks with RegisterStartupScript () and RegisterClientScriptBlock ()

The only difference between the two methods is that each of them emits a Script block. RegisterClientScriptBlock () selects the Script block at the beginning of the web form (immediately after the tag), and RegisterStartupScript () emits a Script block at the end of the web form (right before the </form> ).

+9
source

Source: https://habr.com/ru/post/1305958/


All Articles