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

  • SEARCH
  • Home
  • 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 8216841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:16:19+00:00 2026-06-07T12:16:19+00:00

I’m new to working in ASP.NET but I’m developing a custom control that has

  • 0

I’m new to working in ASP.NET but I’m developing a custom control that has a multi view control inside it that displays a bunch of different stuff. Some of it is displayed using JQuery UI elements like tabs and accordians which will have quite a bit of customisation.

Since I’m going to have a lot of CSS rules that apply only to the elements inside the custom control (not to the rest of our web site), I’m wondering where to put the CSS style rules.

I’d normally just put a style sheet somewhere in the site root and reference it from there. But as I play around with ASP.NET, I get the feeling that I should be putting all my code (including CSS, JS, etc) inside the custom control itself. This feels more “programmy”, keeping everything together.

Can anyone adivse how I should be doing this? What’s the best practice for web development in ASP.NET?

  • 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-06-07T12:16:21+00:00Added an answer on June 7, 2026 at 12:16 pm

    If the control you are creating is in a separate assembly, you can embed the CSS files inside the assembly to make it reusable and create a direct link to these files from your control, then in your control you will register them to be rendered as link tags in your page

    Note: Remember that you need to mark the CSS file in your assembly as an Embedded Resource

    Just select your file | then proeprties and change its Build Action property and set it to: embedded Resource

    enter image description here

    In the following code:

    • AjaxEnabled.Web.UI represents the namespace of your assembly

    • DefaultStyle.css represents the embedded CSS file name

    The following code sample shows the steps needed: (in your custom server control)

    [assembly: WebResource("AjaxEnabled.Web.UI.DefaultStyle.css", "text/css")]
    
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
    
            if (this.Page.Header != null)
            {
                if (!this.Page.ClientScript.IsClientScriptBlockRegistered("defaultCss"))
                {
                    var link = new HtmlLink();
    
                    link.Href = this.Page.ClientScript.GetWebResourceUrl(
                        typeof(YourControlType),
                        "AjaxEnabled.Web.UI.DefaultStyle.css"
                    );
                    link.Attributes.Add("rel", "stylesheet");
                    link.Attributes.Add("type", "text/css");
    
                    this.Page.Header.Controls.Add(link);
                    this.Page.ClientScript.RegisterClientScriptBlock(
                        typeof(Page),
                        "defaultCss",
                        string.Empty
                    );
                }
            }
        }
    

    You need to add an instance of the ScriptManager control in your page containing your custom controls

    <asp:ScriptManager runat="server" ID="sm"/>
    

    And in your ASPX page you need to mark the header section as a server control

    <head runat="server">
    

    The following code:

    link.Href = this.Page.ClientScript.GetWebResourceUrl(
                    typeof(YourControlType),
                    "AjaxEnabled.Web.UI.DefaultStyle.css");
    

    Renders a link directly to the CSS file embedded in the assembly


    This condition:

    if (!this.Page.ClientScript.IsClientScriptBlockRegistered("defaultCss"))
    ...
    this.Page.ClientScript.RegisterClientScriptBlock(
                            typeof(Page),
                            "defaultCss",
                            string.Empty
                        );
    

    ensures that the CSS is rendered only once in the page, even if you drop more than one instances of your control

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported

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.