[ASP.NET 1.1] Changing attribute value

Winston

Junior Contributor
Joined
Jan 25, 2003
Messages
266
Location
Sydney, Australia
Hey does anyone know how i can dynamically change an attribute of tag, in particular i want to change the href attribute in the link tag, any ideas anyone?


thanks.
 
.NET 2.0 offers HtmlLink class, so it's easy to do it. In 1.1 you have to do it a little bit tricky:

html:
<HEAD id="pageHead" runat="server">
<title>WebForm1</title>
<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">
<LINK rel="stylesheet" type="text/css" href="StyleSheet1.css">
</HEAD>

in code:
protected System.Web.UI.HtmlControls.HtmlGenericControl pageHead;

Up now you can access InnerHtml property and change it's content. For example to change href:

pageHead.InnerHtml = pageHead.InnerHtml.Replace("StyleSheet1.css","StyleSheet2.css");

It's not very cool, but I haven't found a way how to add runat="server" attribute directly to <link> tag (I receive parse errors) (BTW. in 2.0 works).

Greets
Adam
 
Back
Top