Find An HTML Control

  • Thread starter Thread starter OldButStillLearning
  • Start date Start date
O

OldButStillLearning

How do you find an HTML control that is placed on an HTML page? I presume
that you have to add the runat="server" to the HTML element..but then how do
you find that element?
 
OldButStillLearning said:
How do you find an HTML control that is placed on an HTML page? I presume
that you have to add the runat="server" to the HTML element..but then how
do
you find that element?

If you add runat="server" then you can access it using its Id:

Default.aspx:

<table runat="server" ID="tblMyTable">
<tr>
<td>Hello!</td>
</tr>
</table>

Default.aspx.vb:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
tblMyTable.Border = 1
End Sub
 
Give it an ID="MyControl".

Then you can "find" it by using the FindControl() method. Or, just access it
directly:

MyControl.Style = "color: red;"
 
Back
Top