Rohit Kesharwani
Rohit Kesharwani

Reputation: 83

How to apply stylesheet in our user control

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 .

Upvotes: 1

Views: 3299

Answers (3)

Arun Rana
Arun Rana

Reputation: 8606

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.

Upvotes: 0

huMpty duMpty
huMpty duMpty

Reputation: 14460

Try this way

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

Hope this helps

Upvotes: 1

Andy Rose
Andy Rose

Reputation: 16974

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)

Upvotes: 4

Related Questions