How to get clientID of text box control which is present within a Grid Control
I have a text box control within a Grid Control. I would like to get the clientID of the textBox using javascript with something like "<%= txtBox.ClientID %>". But I get an error message saying that txtBox does not exist in the current context. The textbox is programmatically created.
Could you let me know how to 开发者_如何学Pythonget the clientID of the textBox.
Thanks
UPDATE: this should work better: <%= myContainer.FindControl("txtBox").ClientID %>
One way would be to put it in a hidden field when you generate the text box:
TextBox txtBox = new TextBox();
txtBox.ID = "txtBox";
Page.ClientScript.RegisterHiddenField("txtBoxClientID", txtBox.ClientID);
and then you can get it on the client-side using
document.getElementById('txtBoxClientID').value
instead of this
jst try out
document.getElementById('ID_OF_THE_CONTROL*').value;
*..the id of the textbox..
精彩评论