SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict itHighway's Avatar
    Join Date
    Jan 2008
    Location
    GUJ
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Master Page and Javascript

    Hi,

    I am new to ASP.net.
    My questions is regarding using Javascript and CSS files in Master Page.

    Suppose I have two pages home.aspx and contact.aspx. Home page uses home.js and contact page requires contact.js. How should I load ONLY home.js file at home page and contact.js file at contact.aspx page in Master file?


    Thanks!
    Zeeshan

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,245
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    The typical way I have approached this in the past is to have the pages themselves add the script in their code behind.

    Example: home.aspx
    Code C#:
    Page.RegisterClientScript(....)

    If you need it to be in the head or within the master page itself, then something like this usually works

    Master Page
    Code C#:
    public function RegisterScriptFile(string filename)
    {
      Page.RegisterClientScript(...);
    }

    Then from your home.aspx
    Code C#:
    protected void Page_Load(object sender, EventArgs e)
    {
      ((MasterPage)Master).RegisterScriptFile("home.js");
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •