Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Prajno Malla 3 posts 23 karma points
    Nov 03, 2009 @ 18:23
    Prajno Malla
    0

    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!

  • Ricky Beard 61 posts 116 karma points
    Nov 03, 2009 @ 18:30
    Ricky Beard
    0

    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.

  • Prajno Malla 3 posts 23 karma points
    Nov 03, 2009 @ 18:34
    Prajno Malla
    0

    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).

  • Ricky Beard 61 posts 116 karma points
    Nov 03, 2009 @ 18:51
    Ricky Beard
    0

    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.

  • Prajno Malla 3 posts 23 karma points
    Nov 03, 2009 @ 19:07
    Prajno Malla
    0

    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! 

Please Sign in or register to post replies

Write your reply to:

Draft