Groups | Blog | Home
all groups > asp.net webcontrols > april 2004 >

asp.net webcontrols : Custom control help


raj.surisetti NO[at]SPAM aeromech.usyd.edu.au
4/20/2004 6:32:36 PM
Hi,

Can anyone help me to build custom control for the following

<HEAD>
<LINK href="~/Styles/Blah.css" rel="stylesheet" type="text/css">
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content =
"http://schemas.microsoft.com/intellisense/ie5">
</HEAD>

to

<FW:Head id="myHead1" Style="~/Styles/Blah.css" Keyword="Blah"
runat="server"/>

I would apperiate any help i can get.

Regards,
raj.surisetti NO[at]SPAM aeromech.usyd.edu.au
4/22/2004 5:10:23 PM
[quoted text, click to view]

This is code

using System;
using System.ComponentModel;
using System.Web.UI;

namespace myNameSpace{
[
DefaultProperty("Stylesheet")
]
/// <remarks>
/// Creates a Head element in HTML with the appropriate attributes as
required by the framework.
/// </remarks>
public class Head : Control, INamingContainer
{
[
Category("Behavior"),
DefaultValue(""),
Description("The html head tag generator for the framework")
]
#region Internal Properties
private String sKeywords = "";
private String sStylesheet = "";
#endregion
#region Properties
public String Keywords
{
get
{
return sKeywords;
}
set
{
sKeywords = value;
}
}

public String Stylesheet
{
get
{
return sStylesheet;
}
set
{
sStylesheet = value;
}
}
#endregion
#region Overrides
// This ensures that there are no child controls.
protected override ControlCollection CreateControlCollection()
{
return new EmptyControlCollection(this);
}
protected override void Render(HtmlTextWriter writer)
{
writer.RenderBeginTag(HtmlTextWriterTag.Head);
if(sStylesheet.Length != 0)
{
writer.AddAttribute( "rel", "stylesheet", false);
writer.AddAttribute( "type", "text/css", false);
writer.AddAttribute( "href", sStylesheet, true);
writer.RenderBeginTag(HtmlTextWriterTag.Link);
writer.RenderEndTag();
}
if(sKeywords.Length != 0)
{
writer.AddAttribute( "name", "keywords", false);
writer.AddAttribute( "content", sKeywords, true);
writer.RenderBeginTag(HtmlTextWriterTag.Meta);
writer.RenderEndTag();
}
writer.RenderEndTag();
}
#endregion
}
}


cheers,
AddThis Social Bookmark Button