change attribute in html elements

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
 
S

suzy

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.!
 
S

S. Justin Gengo

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
 

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
474,265
Messages
2,571,069
Members
48,771
Latest member
ElysaD

Latest Threads

Top