Winston Posted July 4, 2005 Posted July 4, 2005 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. Quote
Administrators PlausiblyDamp Posted July 4, 2005 Administrators Posted July 4, 2005 If you are using a hyperlink control rather than just coding the link in html you can just assign a new value to it's .NavigateUrl property. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Winston Posted July 5, 2005 Author Posted July 5, 2005 Ummmm this link tag is for my stylesheet, i should of stated earlier, sorry. Quote
hrabia Posted July 5, 2005 Posted July 5, 2005 .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 Quote A man and a dog have an average of three legs. Beaware of Statistics.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.