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
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif 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
http://msdn.microsoft.com/subscriptions/support/default.aspx. ==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.