uzay95
uzay95

Reputation: 16622

Appending javascript code piece to the end of the body tag

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

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

is appending to body but js codes are always requesting some js files didn't load or some functions are below of the script.

How can i append scripts that i generated dynamically to the bottom of body?

Thanks for your help.

Upvotes: 6

Views: 7741

Answers (2)

uzay95
uzay95

Reputation: 16622

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

The only difference between these two methods is where each one emits the script block. RegisterClientScriptBlock() emits the script block at the beginning of the Web Form (right after the tag), while RegisterStartupScript() emits the script block at the end of the Web Form (right before the </form> tag).

Upvotes: 11

Tomas Vana
Tomas Vana

Reputation: 18775

We are using 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 that will help ;)

Upvotes: 12

Related Questions