Search For An HTML Tag

J

Jim Heavey

If I have a <div id='fred' runat='server'> embedded in my HTML page, how
can I find this tag in my code and change some its' characteristics?
 
K

Ken Cox [Microsoft MVP]

Hi Jim,

You can create an instance of the HTMLGenericControl, get a handle on your
div and mess with the properities as shown below. Is this what you need?

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim divHTML As _
System.Web.UI.HtmlControls.HtmlGenericControl
divHTML = Page.Controls(1).FindControl("fred")
divHTML.Attributes.Add("Style", "COLOR: red")
End Sub

<form id="Form1" method="post" runat="server">
<div id='fred' runat='server'>Change Colour</div>
<asp:Button id="Button1" runat="server" Text="Change"></asp:Button></DIV>
</form>

Ken
Microsoft MVP [ASP.NET]
Toronto
 

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
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top