Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. User Controls, Master Pages, CSS and putting it all together

User Controls, Master Pages, CSS and putting it all together

Scheduled Pinned Locked Moved ASP.NET
questioncsswinformshelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RX Maverick
    wrote on last edited by
    #1

    I have a master page (MasterPage.master) and it's called by Default.aspx. Then I added a web user control (WebUserControl.ascx), I tested it all and everything was working great. I decided to add some color to the user control by way of CSS (StyleSheet.css), now I have problems. I don't want to add a link to the MasterPage head since not all pages using the master need the css. How do I programmatically have my WebUserControl.ascx.vb add a link tag to my page head? I think I explained this well, but if not just post your questions and I'll try to answer them. Thanks for any help offered.

    A M 2 Replies Last reply
    0
    • R RX Maverick

      I have a master page (MasterPage.master) and it's called by Default.aspx. Then I added a web user control (WebUserControl.ascx), I tested it all and everything was working great. I decided to add some color to the user control by way of CSS (StyleSheet.css), now I have problems. I don't want to add a link to the MasterPage head since not all pages using the master need the css. How do I programmatically have my WebUserControl.ascx.vb add a link tag to my page head? I think I explained this well, but if not just post your questions and I'll try to answer them. Thanks for any help offered.

      A Offline
      A Offline
      Anbuselvan
      wrote on last edited by
      #2

      Hi, There are two ways available to resolve your issue. 1. Simple and easy way. Put all your CSS styles in a style sheet and save into your project. string should be: Add the following code to your control's page load event: Page.ClientScript.RegisterClientScriptBlock(GetType(), , , false); 2. Some more work but efficient. Create a function in for your master page like, public void AddCssLink(string cssfile) { HtmlGenericControl styleCtrl = new HtmlGenericControl("link"); styleCtrl.Attributes.Add("href", "Styles/" + cssfile); styleCtrl.Attributes.Add("rel", "stylesheet"); styleCtrl.Attributes.Add("type", "text/css"); Page.Header.Controls.add(styleCtrl); } from your control's page load event, Master.AddCssLink(""); Happy programming. With Best Regards, P.Anbuselvan IT Consultant Emirates Group IT, UAE

      1 Reply Last reply
      0
      • R RX Maverick

        I have a master page (MasterPage.master) and it's called by Default.aspx. Then I added a web user control (WebUserControl.ascx), I tested it all and everything was working great. I decided to add some color to the user control by way of CSS (StyleSheet.css), now I have problems. I don't want to add a link to the MasterPage head since not all pages using the master need the css. How do I programmatically have my WebUserControl.ascx.vb add a link tag to my page head? I think I explained this well, but if not just post your questions and I'll try to answer them. Thanks for any help offered.

        M Offline
        M Offline
        minhpc_bk
        wrote on last edited by
        #3

        I think there are many ways to do what you want. You can programmatically access the Header[^] of the current page using the Page.Header[^] property and simply add the stylesheet. You can also do as someone said by injecting text or control (should use the HtmlLink Class instead of the generic one).

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups