How to access the controls that are inside of a DataList/DataGrid using JS?

R

Renato Neves

My problem is simple, i have a datalist control with some controls inside of
EditTemplate (the problem is the same in the DataGrid). I want to have
access to this controls, using javascript, but
i can't. How can i do this?


<Code>
<script language="javascript">
document.getElementById('<%=txt1.ClientID %>').value='test';
document.getElementById('<%=txt2.ClientID %>').value='test';
</script>
....

<asp:DataList id="Test" ...><EditItemTemplate>
<asp:textbox id="txt1" runat=server></asp:textbox></EditItemTemplate>
</asp:DataList>...

<asp:textbox id="txt2" runat=server></asp:textbox>
</Code>


The first case, don't have success, but the second i can write to textbox.
The problem is that the client side ID of txt1 is "_ctl0:Test:_ctl0:txt1"
(different of txt2 ID ["_ctl0:txt2"]).

I have read this problem somewhere, but now i can't find it! :/
Can anyone help me?

Thanks
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top