Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

.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

A man and a dog have an average of three legs.

Beaware of Statistics.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...