Sunday, 4 March 2012

How to Programmatically add JavaScript File to Asp.Net page?


If you do not want to add your JavaScript files declaratively via HTML to your ASP.Net page, you can do it in code, and here is how:

Just add this code to the Page_Init event handler on your page:
    protected void Page_Init(object sender, EventArgs e)
    {

        HtmlGenericControl js = new HtmlGenericControl("script");
        js.Attributes["type"] = "text/javascript";
        js.Attributes["src"] = "jscript/formfunctions.js";
        Page.Header.Controls.Add(js);

    }

And thats all there is to it Description: http://www.aspdotnetfaq.com/fckeditor/editor/images/smiley/msn/wink_smile.gif.
Post a Comment