Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  7] [ 1]  / answers: 1 / hits: 60199  / 15 Years ago, wed, july 15, 2009, 12:00:00

I have a asp:GridView which contains a asp:TextBox within a TemplateField. I would like to obtain it's ID for use in javascript. Something like this:



<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID=textDateSent runat=server />
<input type=button value='Today'
onclick=setToday('<%# textDateSent.ClientID %>'); />
</ItemTemplate>
</asp:TemplateField>


But when I compile, I get an error:




The name 'textDateSent' does not exist in the current context




Anybody know how to get the client ID of this TextBox?


More From » asp.net

 Answers
55

Try this:



<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID=textDateSent runat=server>
</asp:TextBox>
<input type=button value='Today' onclick=setToday('<%# ((GridViewRow)Container).FindControl(textDateSent).ClientID %>'); />
</ItemTemplate>
</asp:TemplateField>

[#99125] Thursday, July 9, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
katelinb

Total Points: 535
Total Questions: 104
Total Answers: 109

Location: Burkina Faso
Member since Sun, Jun 13, 2021
3 Years ago
;