control to add <LINK> inside <HEAD>

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default control to add <LINK> inside <HEAD>

    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.


    Oleg Ogurok Guest

  2. Similar Questions and Discussions

    1. Validator for server control inside user control
      Hello, I am facing a strange situation and have already spent a lot of time on this. I have a user control 'U' that consists of a...
    2. Modify Head Tag from Custom Control.
      Can I or how do I modify the Head Tag using a Custom Control. I've tried adding a Literal Control and setting it's "Text" property. I get access...
    3. Link inside xml-text
      Hi I have problem in html links. I using eternal xml-file to hold my my textArea text in flash. I have programmed so that one xml node is for...
    4. How to draw an arrow head inside a path?
      Hi, when I add the arrow effect to a path, the arrow head exceeds the path endpoint due to the fact that the arrow center is placed at the anchor...
    5. get head by tagname (from server control)
      my server control generates part of page from codebehind. I get other part from different source. how can i get <head></head> (written inline on...
  3. #2

    Default here is a sample code


    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


    webgenie Guest

  4. #3

    Default Re: here is a sample code


    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" <geniex@msn.com> wrote in message news:un3mLaPfDHA.2352@TK2MSFTNGP12.phx.gbl...

    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


    Oleg Ogurok Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139