change attribute in html elements

  • Thread starter Thread starter Linus Martinsson
  • Start date Start date
L

Linus Martinsson

How can I change attribute in html elements from my aspx.cs page?



For example if I want to change the src-attribute in an iframe.



//Linus
 
when i want to change the attribute of a htmlcontrol in c#, i use:

HtmlControl.Attributes["attributename"] = "attributevalue"

eg: oHtmlTableCell.Attributes["class"] = "headercell";

hope this helps you.!
 
Make the html object into a server side control.

1) Add and id="myobject" and runat="server" attributes to the object in the
html code:

<iframe id="MyIframe" runat="server"></iframe>

2) Dim the object in your codebehind page as a
System.Web.UI.HtmlControls.HtmlGenericControl:

Protected MyIframe As System.Web.UI.HtmlControls.HtmlGenericControl

3) Now you may add attibutes dynamically as suzy suggests.

MyIframe.Attributes.Add("[Attribute Name]", "[Attribute Value]")

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
Back
Top