1

I have createa a user control and apply a style shet.

When i add this user control on my asp.net web forms style shet will not apply. I don't want to add reference of stylesheet file in my asp.net page

Pls. help me.

Thanks .

  • Related thread - http://stackoverflow.com/questions/34390/how-to-make-user-controls-know-about-css-classes-in-asp-net – KV Prajapati Oct 18 '11 at 11:48

3 Answers3

4

Links to stylesheets need to be applied in the HEAD section of your html. If you don't want to reference the style sheet in your asp.net page directly you can either use inline styles in you user control or add the reference in the user controls code behind file. The following code is in VB.NET and was taken from an answer in this forum:

Dim Style As New HtmlControls.HtmlLink

With Style.Attributes
.Add("href", Me.ResolveUrl(Me.AppRelativeVirtualPath).Replace(" .ascx", ".css"))
.Add("type", "text/css")
.Add("rel", "stylesheet")
End With

Page.Header.Controls.Add(Style)
Andy Rose
  • 16,770
  • 7
  • 43
  • 49
1

Try this way

<link rel="Stylesheet" type="text/css" href="<%=ResolveUrl("~/yourpath.css") %>" />

Hope this helps

huMpty duMpty
  • 14,346
  • 14
  • 60
  • 99
0

Generally under in web.config you need to

  1. add <pages theme="skinfile" styleSheetTheme="Default">
  2. on root of your application Add APP_Themes asp.net folder and
  3. Under that folder create 2 folder called Default for stylesheet and skinfile folder for skinfile

So that would be available throughout the application.

huMpty duMpty
  • 14,346
  • 14
  • 60
  • 99
Arun Rana
  • 8,426
  • 14
  • 67
  • 107