Skip to main content

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

In this post I will show you how to add JavaScript files programmatically  to your page. 

Just add this code to the Page_Init event handler on your page:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Blog_Tips.aspx.cs" Inherits="Blog_Tips" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        How to Programmatically add JavaScript File to Asp.Net page?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class Blog_Tips : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)


    protected void Page_Init(object sender, EventArgs e)
        HtmlGenericControl javascript = new HtmlGenericControl("script");
        javascript.Attributes["type"] = "text/javascript";
        javascript.Attributes["src"] = "Scripts/jquery-1.3.2.min.js";


  1. thank you for your topics ..
    that is good for all asp developer ..


Post a Comment

Popular posts from this blog