HELP: (ASP.NET 2.0) - Can't get CSS HtmlLink Element working in VS Designer

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

  1. #1

    Default HELP: (ASP.NET 2.0) - Can't get CSS HtmlLink Element working in VS Designer

    Hi,

    I've got the following problem: In my client's project I've created an ASP.NET Custom Control to add CSS style sheet HtmlLink elements to a page dynamically. But I can't get this control to work in VS Designer. Thus my co-workers can't create their pages as expected.

    !! Please note that I don't have write access to newsgroups at my client so I'm trying to be as precise as possible. I can't reply to questions during the week. !!


    This is my set-up:

    My control (MyStyleLink) resides in the <header> section of the master page:

    <%@ Master Language="C#" ... %>
    <html ...>
    <head>
    <uc1:MyStyleLink runat="server" />
    ...
    </head>
    ...


    That's what's working:

    The control renders a bunch of <link type="text/css" rel="stylesheet" href="...."> elements in the master page's <header> section using the Render() method. It creates a CSS link constructed from the master page file path, a second link constructed from the page file path and additional links for each User Control (.ascx) in the page, constructed from each control's file path.


    Here's what's NOT working (corresponding questions follow below):

    I've created a Designer class derived from ControlDesigner, assigned it to the MyStyleLink class, implemented a GetDesignTimeHtml() method and tried to have it create the same link elements the control creates at runtime. My issues:

    a) At design time, none of the document paths is available,
    neither Page.MasterPageFile
    nor Request.Url
    or TemplateControl.AppRelativeVirtualPath or Page.AppRelativeVirtualPath.
    They all are null (which I noticed debugging my devenv process).

    b) If I hard-code a <link> into the master page, it works in Designer as well.
    If I now use this exact <link> as return value to GetDesignTimeHtml(), like:

    public override string GetDesignTimeHtml()
    {
    return "<link .... />";
    }

    it doesn't.

    c) I tried a third approach, using the control's OnInit() event to add
    HtmlLinks to the master page. Yet I get an HttpException telling me that
    I can't add controls to the Controls collection on Init, Load, DataBinding
    etc. ("HttpException: The control collection cannot be modified during
    DataBind, Init, Load, PreRender or Unload phases.")


    My Questions:

    a) Why are all the paths null?
    b) Why can't I get my control to render the <link> element in Designer?
    c) Why can't I add controls to the master pages Header section?


    Here's my final (and most important) question:

    How can I get my control to work at all ???


    TIA,
    Axel Dahmen

    Axel Dahmen Guest

  2. Similar Questions and Discussions

    1. Why can't got element from XML
      I try to load an XML element from an XML file using HTTPService Object . But The loaded object always null . Here is my XML Content <?xml...
    2. Are you the designer i am looking for?
      Dear designer, Do you often wonder who built a certain website and how it is done? And who manages that website right now? Strange, but...
    3. Need a designer - willing to pay
      Guys, I am about to purchase a Flash templates from Template Monster. I am currently working with a NASCAR Stock-car driver on a Flash Intro,...
    4. [HTML::Element] how to read element by element
      Hello I read the doc about HTML::Element, but I don't find how to read the tree create by parse() element by element. The doc says the tree looks...
    5. Look for a web designer
      I'm working on an OpenSource project, and I'm looking for a web designer to write and administer the web site associated with the project. The...
  3. #2

    Default RE: HELP: (ASP.NET 2.0) - Can't get CSS HtmlLink Element working in VS Designer

    Hi Axel,

    Based on my understanding, you're creating a custom server control that is
    designed to insert dynamic stylesheet links into the master page's header
    according to different content page and user controls used on the WebForm.
    This is working correctly at runtime, but you found it's not working at
    design-time.

    Please correct me if I've misunderstood anything.

    I've done some research and consulting with my colleagues, I'm afraid this
    is not possible to change the stylesheet of the master page at runtime
    using custom server control.

    As you've already discovered, to support design-time behavior, we need to
    provide a control designer and overrides either GetDesignTimeHtml() or
    GetEmptyDesignTimeHtml(), GetErrorDesignTimeHtml(). However, html returned
    from these methods are merely used to show a preview image to the user
    instead of directly injecting the html into the web page. Since <link>
    elements are used to change the dynamic behavior of a html page instead of
    has a own UI to represent, it's not possible for a control designer to add
    links into the host web form.

    As for the relevant properties don't have value at design-time, it's
    because most of the services need HttpContext to function properly, and
    it's not available at design-time.

    The exception in OnInit() you're seeing is because adding controls at these
    places will make asp.net fail to load viewstate later since viewstate is
    restored based on control hierarchy and position.

    In summary, I'm afraid it's not possible to change the stylesheet links at
    design-time using a custom server control.



    Sincerely,
    Walter Wang (wawang@online.microsoft.com, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    Get notification to my posts through email? Please refer to
    [url]http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif[/url]
    ications. If you are using Outlook Express, please make sure you clear the
    check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
    promptly.

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    [url]http://msdn.microsoft.com/subscriptions/support/default.aspx[/url].
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.

    Walter Wang [MSFT] 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