I created a UserControl to apply a stylesheet to the header of a page dynamically. The control works great on a web application but I can't get the following line to work:
Page.Header.Controls.Add(link);
The Page object is null and crashes. How else can I access a page control? If this is not the best way, is there a way to populate a literal control on the template from the UserControl? I've searched everywhere and tried multiple approaches and am getting nowhere. Thank you in advance!
I usually create a content placeholder in the <head> of my master template so that I can pass any js or css script references that I wish from any child. I wrote a quick how-to on this that you can read here. This does not require a User Control at all.
Thanks for the tip and quick reply. The reason I'm using a UserControl is that I get user input regarding font size (small,medium,large) and store it in a session variable (as opposed to javascript font size solutions which need do not maintain state).
I see. You can still place the User Control in the <head> of your Master Template via a macro, then simply output the stylesheet reference as html using a literal based on info from the session variable. That would keep you from having to target the Master Template directly from your User Control.
Thank you for the suggestion. I broke up the User Control into 2 (one for input controls, the other to render the css link off of the session variable). It's working properly now!
Accessing Page object from UserControl
Hello,
I created a UserControl to apply a stylesheet to the header of a page dynamically. The control works great on a web application but I can't get the following line to work:
Page.Header.Controls.Add(link);
The Page object is null and crashes. How else can I access a page control? If this is not the best way, is there a way to populate a literal control on the template from the UserControl? I've searched everywhere and tried multiple approaches and am getting nowhere. Thank you in advance!
I usually create a content placeholder in the <head> of my master template so that I can pass any js or css script references that I wish from any child. I wrote a quick how-to on this that you can read here. This does not require a User Control at all.
Thanks for the tip and quick reply. The reason I'm using a UserControl is that I get user input regarding font size (small,medium,large) and store it in a session variable (as opposed to javascript font size solutions which need do not maintain state).
I see. You can still place the User Control in the <head> of your Master Template via a macro, then simply output the stylesheet reference as html using a literal based on info from the session variable. That would keep you from having to target the Master Template directly from your User Control.
Thank you for the suggestion. I broke up the User Control into 2 (one for input controls, the other to render the css link off of the session variable). It's working properly now!
is working on a reply...