Does anyone know if it's possible to use sys.application.on_init(), or some other feature of the MS AJAX client-side library, to cause the client browser to load a specific CSS file?
I have a user control that needs to load a css file based on a design time setting. The problem is that, since there's a MasterPage involved, I don't seem to be able to update the Page.Header control collection. It works if the user control is on a stand
alone aspx (see code below), but throws the following exception when a MasterPage is introduced:
The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.
I was hoping that, since the MasterPage has the ScriptManager control in place, there might be a way to let the User Control register the loading of the css file using the client-side AJAX library. Any help would be appreciated!
dotnetorbust
Member
29 Points
19 Posts
Client Side load of CSS file
Dec 20, 2007 07:05 PM|LINK
Does anyone know if it's possible to use sys.application.on_init(), or some other feature of the MS AJAX client-side library, to cause the client browser to load a specific CSS file?
I have a user control that needs to load a css file based on a design time setting. The problem is that, since there's a MasterPage involved, I don't seem to be able to update the Page.Header control collection. It works if the user control is on a stand alone aspx (see code below), but throws the following exception when a MasterPage is introduced:
The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.
I was hoping that, since the MasterPage has the ScriptManager control in place, there might be a way to let the User Control register the loading of the css file using the client-side AJAX library. Any help would be appreciated!
protected void Page_Load(object sender, EventArgs e) { HtmlLink link2 = new HtmlLink();link2.Href = Page.ResolveUrl(
"~/Controls/CSS/" + cssFileID + ".css"); link2.Attributes.Add("type", "text/css");link2.Attributes.Add("rel", "stylesheet");Page.Header.Controls.Add(link2);
}
gt1329a
All-Star
15377 Points
2501 Posts
ASPInsiders
MVP
Re: Client Side load of CSS file
Dec 20, 2007 07:50 PM|LINK
Add runat="server" to the <head> tag on the master page, and it should work.
A guide to combining jQuery and ASP.NET: jQuery for the ASP.NET developer
dotnetorbust
Member
29 Points
19 Posts
Re: Client Side load of CSS file
Dec 20, 2007 09:15 PM|LINK
Thanks for your reply, E !!
That was it.