Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 534367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:36:18+00:00 2026-05-13T09:36:18+00:00

I am struggling with something that I guess should be standard practice really. I

  • 0

I am struggling with something that I guess should be standard practice really. I have a number of user controls that use some JQuery plugins. I do not really want to link to the extra CSS and JS files from my main masterpage as this would cause extra load to the user the first time they hit the site, (admittedly it would only be the once), so I was just putting them links into the top of the user control. Then I looked at my source HTML, not nice! Even worse for controls that repeat multiple times on a page.

So I was thinking is there a way of injecting them into the Head of the page when they are needed from the User Control. For that matter is there a way of doing it to the footer for JS stuff?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:36:18+00:00Added an answer on May 13, 2026 at 9:36 am

    To dynamically register a script (and ensure that duplicates are merged) in ASP.NET you can call:

    Page.ClientScript.RegisterClientScriptInclude(
        "mykey", "~/scripts/jquery-1.3.2.js");
    

    And read the full details on this method on MSDN.

    To add CSS dynamically you can do something like this:

    HtmlLink cssLink = new HtmlLink();
    cssLink.Href = "path to CSS";
    cssLink.Attributes["some attr1"] = "some value1";
    cssLink.Attributes["some attr2"] = "some value2";
    Page.Header.Controls.Add(cssLink);
    

    This example of injecting CSS will not merge duplicate entries. To avoid duplication you’ll have to keep track of duplicates yourself. One place you can store a list of scripts you’ve already registered is in HttpContext.Items. Stick a HashSet in there that keeps a list of all registered scripts so that you don’t register the same CSS file twice (which is generally harmless, but something to avoid anyway).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm really struggling with something that should be a simple matter: Showing a user
I'm struggling with something that should be really easy I think. I have a
I am struggling on something that, I am sure, should be easy. I have
I am struggling with something that I think should be easily (ish). I have
I've been struggling with something at work that I'm not really in the mood
I'm really struggling trying to find something that actually works for getting the basics
I'm struggling with something that I expect should be fairly straightforward! - is it
I've really been struggling to make SQL Server into something that, quite frankly, it
I am struggling with something that I'm not even sure if possible. I have
I'm struggling with something that I am sure has a very simple method, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.