A
Axel Dahmen
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
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