Results 1 to 2 of 2

Thread: Custom Control grabs parent page's elements?

  1. #1

    Thread Starter
    Addicted Member WALDO's Avatar
    Join Date
    Aug 2002
    Location
    Swing of Prussia, PA
    Posts
    244

    Custom Control grabs parent page's elements?

    I was wondering...

    How could I grab the <HEAD> tag of the parent page of a Custom Control?

    I'm basically writing a client-side calendar control that has style properties that i would like to set via a style sheet, rather than implementing my own font properties.

    I want to be able to grab the <HEAD> tag of the parent page (either as an object or text) and parse it to determine if my <LINK> tag has been applied. If it has not, then I want to add the tag programmatically. I could apply the same concept to script with
    IsClientScriptBlockRegistered and

    RegisterClientScriptBlock

    but how can I do this for a <LINK> tag or a <STYLE> tag?

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    I actually do the same thing in my forums. I dynamically load a stylesheet and populate other various data within the head tag. I built a custom control that extends the literal control. Here is the code:

    NOTE: You could also use a databinding expression within the head tag.

    Code:
    namespace VegaSoft.VSForums.Controls
    {
    	using System;
    	using System.Web;
    	using System.Web.UI;
    	using VegaSoft.VSForums.Web;
    	using VegaSoft.VSForums.Config;
    
    	public class SkinManager : LiteralControl
    	{
    		public SkinManager() 
    		{	
    			string content = "";
    			if (ActiveUser.IsLoggedIn())
    				content = String.Format("<title>Vega Forums Message Board (Logged in as: {0})</title>", ActiveUser.Name);
    			else
    				content = "<title>Vega Forums Message Board</title>";
    				
    			content += String.Format("\n<link href='{0}style/styles.css' type='text/css' rel='stylesheet' />", ActiveUser.PathToSkin);
    			content += String.Format("\n<script src={0}></script>", Configuration.PathToScripts);
    			base.Text = content;
    		}
    	}
    }
    Last edited by Lethal; Jul 3rd, 2003 at 10:25 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width