Custom control help

R

RajSurisetti

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,
RajSurisetti.
 
R

RajSurisetti

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,
RajSurisetti.

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,
RajSurisetti
 
M

Matt Berther

Hello (e-mail address removed),

If I'm not mistaken, this code will write out in this format...

<html>
<body>
<head>...</head>
</body>
</html>

instead of the expected format where <head>...</head> would be a child of <html>.
 
R

RajSurisetti

Matt Berther said:
Hello (e-mail address removed),

If I'm not mistaken, this code will write out in this format...

<html>
<body>
<head>...</head>
</body>
</html>

instead of the expected format where <head>...</head> would be a child of <html>.

Hi Matt,

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

Generated HTML code

<HEAD>
<LINK href="~/Styles/Blah.css" rel="stylesheet" type="text/css">
<meta name="Keyword" Content="Blah">
</HEAD>

you can add as many meta tags you want.
I used same logic for Breadcrumbs and it worked fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top