Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > control to add <LINK> inside <HEAD>

Reply
Thread Tools

control to add <LINK> inside <HEAD>

 
 
Oleg Ogurok
Guest
Posts: n/a
 
      09-10-2003
Hi all,

I'm building a custom control, which has a separate .css file with its
stylesheet. I need to link to the stylesheet inside the page, e.g.:
<link rel="stylesheet" href="path/to/sheet.css" type="text/css">

I understand according to HTML standards, I can only add a <link> element
inside <HEAD>.
Is there a method similar to Page.RegisterStartupScript() that emits text
inside <HEAD> element rather than inside <BODY>?

Thanks,

Oleg.


 
Reply With Quote
 
 
 
 
webgenie
Guest
Posts: n/a
 
      09-17-2003

in WebForm1.aspx

<%@ Page Language="C#" Src="WebForm1.aspx.cs" %>
<html>
<head id="head1" runat="server"></head>
<body></body>
</html>


in WebForm1.aspx.cs

public class WebForm1 : System.Web.UI.Page {
//variable for <HEAD> tag.
//because of runat="server" attribute, <HEAD> tag become an instance of HtmlCotnainerControl class.
protected System.Web.UI.HtmlControls.HtmlContainerControl head1;

private void Page_Load(object sender, EventArgs e) {
//declare string variable for <LINK> tag to add inside of <HEAD> tag
string link = "<link rel=\"stylesheet\" type=\"text/css\" href=\"url_of_your_css_file\">";
head1.Controls.Add(new LiteralControl(link));
}
}//end of class WebForm1


 
Reply With Quote
 
 
 
 
Oleg Ogurok
Guest
Posts: n/a
 
      09-17-2003

Thanks, very impressive.
Is there a way to modify the standard ASPX template in VS.NET to generate this code each time a user adds an ASPX file to a project?

-Oleg.
"webgenie" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...

in WebForm1.aspx

<%@ Page Language="C#" Src="WebForm1.aspx.cs" %>
<html>
<head id="head1" runat="server"></head>
<body></body>
</html>


in WebForm1.aspx.cs

public class WebForm1 : System.Web.UI.Page {
//variable for <HEAD> tag.
//because of runat="server" attribute, <HEAD> tag become an instance of HtmlCotnainerControl class.
protected System.Web.UI.HtmlControls.HtmlContainerControl head1;

private void Page_Load(object sender, EventArgs e) {
//declare string variable for <LINK> tag to add inside of <HEAD> tag
string link = "<link rel=\"stylesheet\" type=\"text/css\" href=\"url_of_your_css_file\">";
head1.Controls.Add(new LiteralControl(link));
}
}//end of class WebForm1


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
not declared error- control inside a control inside a webform DC Gringo ASP .Net 4 12-17-2007 02:22 AM
How to add DropDownList Control inside ReportViewer Control. Sevu ASP .Net 5 04-28-2007 02:37 PM
Accessing USER CONTROL which is inside Masterpagethrough Another USER Control inside normal page. Kiran More ASP .Net Web Controls 2 11-14-2006 12:58 PM
Access a control inside an usercontrol from another control inside another usercontrol nail ASP .Net 0 09-15-2004 03:55 PM
not declared error- control inside a control inside a webform DC Gringo ASP .Net Web Controls 3 09-14-2004 09:29 PM



Advertisments