Find An HTML Control

  • Thread starter OldButStillLearning
  • 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?
 
L

Leon Mayne

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
 
S

Scott Roberts

Give it an ID="MyControl".

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

MyControl.Style = "color: red;"
 

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

Top