Mangled id attributes

R

Roshawn Dawson

Hi,

I've noticed that templated controls (DataList and Repeater in
particular) mangle the id attributes of the server controls that are
housed in the ItemTemplate & AtlernatingItemTemplates. I was wondering
if there's a way to "demangle" the id attributes of the server controls
contained in these templates via Javascript.

Thx,
Roshawn
 
B

Brock Allen

No, but you can get the correct ID via Control.ClientID. This is the ID to
use in your javascript.

<script language=javascript>
function SayHello()
{
var ctrl = document.getElemntById('<%= _tb.ClientID %>');
alert(ctrl.value);
}
</script>

<asp:TextBox runat=server id=_tb ... />
 
H

HoustonFreeways

For datagrids, I've found that it is best to refer to the position of the
control in the cell. For example, if you have a textbox, placeholder, and
htmlinputhidden in a cell you can access the placeholder at ItemDataBound
with

ph = CType(e.Item.Cells(1).Controls(1), PlaceHolder)


On the postback you can loop through the datagrid and get elements like this

For Each dgi As DataGridItem In dg_questions.Items

Dim controlType As String =
dgi.Cells(1).Controls(1).Controls(0).GetType.Name

..
..
 

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,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top