Dynamic ID for HTML controls

D

dageyra

I have an HTML server control such as:

<table>
<tr>
<td id="someID1" runat="server"></td>
<td id="someID2" runat="server"></td>
</tr>
</table>

The user has been filling out a multipage form that corresponds to
someID1 and someID2, and I now want to fill in the cells with their
input:

someID1.innerHTML = "string of answers"
someID2.innerHTML = "string of answers"

However, I'm using a loop for this, meaning that someID1 and someID2
will be variable. I am now traversing through the controls on the page
like so:

Dim c as Control
actions = Session("actions")

For Each c In Controls
If (IsInArray(c.ID, actions)) Then
...
End If
Next


Inside the inner If loop, I want to use the Control c to set the
innerHTML or innerText. Is this possible? I have the MSDN reference
for control, but I'm not sure which property/method I can use to do
this. Basically, if the ID of the control is found in actions, I want
to perform operations on it just as if I did

someID.innerHTML = "some text"
 
A

a113n

Issue resolved with the following code:

Dim c as Control
actions = Session("actions")
For Each c in Controls
If TypeOf(c) is HTMLTableCell Then ' Check the type before casting
Dim htmlCtrl As HTMLTableCell = CType(c, HTMLTableCell)
htmlCtrl.InnerHTML = "hello, world"
End If
Next
 

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,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top