\". But I get an error message saying t" />
开发者

How to get clientID of text box control which is present within a Grid Control

开发者 https://www.devze.com 2022-12-12 04:59 出处:网络
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 t

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..

0

精彩评论

暂无评论...
验证码 换一张
取 消