linking Style sheet in User control

G

Gopalan

Hi

I want to use the <link href="...." type="..."> tag inside the .aspx file.
This style is used by the user control (converting an existing aspx file to
ascx file) which are added to this aspx page.
Please tell me where to put it. It is not working properly now.

Thanks

Bhuvanesh
 
G

Gopalan

Hi

I was using <link href="...." type="..."> tag inside the .aspx file.

When I converted this aspx file to ascx file and use it in an aspx file it
is not working properly.

Please tell me where to put it.

Thanks

GB
 
M

Mark Rae

I was using <link href="...." type="..."> tag inside the .aspx file.

When I converted this aspx file to ascx file and use it in an aspx file it
is not working properly.

Please tell me where to put it.

Could it be that the aspx file that you've added your contol into is not at
the same level of the web folder structure relative to the web root...?
 
G

Gopalan

Hi again

Yes

1. the new aspx file is in the root level
2. ascx files are in a subfolder from the root
3. css files are in another subfolder from the root

This is the basic structure I want to maintain to group different types of
files.

Please tell me where I have to change in the code, or any other alternative
method? (one thing I can do is inline style for the ascx file, but it is
tedious to maintain the look and feel in all pages like this)


Thanks
 
Joined
Dec 16, 2008
Messages
1
Reaction score
0
Link stylesheet into page

This piece of code will add the stylesheet into the page where the user control is included.

string relativepath = Page.AppRelativeVirtualPath;

char[] chars = relativepath.ToCharArray();
int counter = 0;

foreach (char c in chars)
{
if (c == '/')
{
counter++;
}
}

string starturl = String.Empty;
for (int i = 1; i < counter; i++)
{
starturl += "../";
}

HtmlGenericControl link = new HtmlGenericControl("link");
link.Attributes.Add("rel", "stylesheet");
link.Attributes.Add("type", "text/css");
link.Attributes.Add("href", starturl + "controls/stylesheet.css");
Controls.Add(link);
Page.Header.Controls.Add(link);

Good luck
Hallgeir
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,406
Latest member
ElizabetMo

Latest Threads

Top