Search For An HTML Tag

  • Thread starter Thread starter Jim Heavey
  • Start date Start date
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?
 
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
 
Back
Top