Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 518
uzay95 Avatar asked Apr 04 '10 10:04

uzay95


2 Answers

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 ;)

like image 167
Tomas Vana Avatar answered Nov 09 '22 12:11

Tomas Vana


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

like image 22
uzay95 Avatar answered Nov 09 '22 11:11

uzay95