aspx Tutorial

NET Articles,jQuery demo, asp.net with jQuery, online tutorial,Jquery, SilverLight, Javascript, asp.net,JSON, MVC,.NET Articles,demo, Web Services,
Advertise Here

Toolbar

Get our toolbar!

Advertize



Posted by Aamir Hasan   on Monday, November 1, 2010 Total Views:  

In this article I have told you that how to append javascript link under the head section. HTMLGenericControl is server control which provide html control tags which are <body>, <head>, <div>,<p>,<li> elements etc.

Here's is the solution


    protected void Page_Load(object sender, EventArgs e)

    {

        HtmlGenericControl JSFile = new HtmlGenericControl();

        JSFile.TagName = "script";

        JSFile.Attributes.Add("type", "text/javascript");

        JSFile.Attributes.Add("language", "javascript");

        JSFile.Attributes.Add("src", ResolveUrl("Scripts/script.js"));

        this.Page.Header.Controls.Add(JSFile);

    }


Note: Add “System.Web.UI.HtmlControls” namespace to load HtmlGenericControl class

Output

Download

JSFile.zip (137.85 kb)

See live demo

Protected by Copyscape Online Plagiarism Tool

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5