开发者

Finding control

开发者 https://www.devze.com 2022-12-10 18:22 出处:网络
The following does not work: var EtxtDOB = $get(\'<%=FormView1.FindControl(\"frmEd开发者_开发问答itPerson\").FindControl(\"EtxtDOB\").ClientID %>\');

The following does not work:

var EtxtDOB = $get('<%=FormView1.FindControl("frmEd开发者_开发问答itPerson").FindControl("EtxtDOB").ClientID %>');

How can I find this nested control in javascript?


I find it's a lot clearer code-wise to explicitly emit the IDs of the controls you want to access via Javascript in the page's code-behind. Something like:

Page.RegisterClientScriptBlock("clientIDs", "var myControlID = '" + myControl.ClientID + "';");

Then you can access this anywhere in your client-side script and it's a lot cleaner:

var ExtODB = getElementById(myControlID);

If you want to get fancy create a utility function that does this for you... or create a custom attribute that automatically does this.


Usually you use 'getElementById' or similar from Javascript. If your control is named 'EtxtDOB' then this might work for you:


document.getElementById('EtxtDOB').setAttribute()....

(Not sure what the $get refers to...)

0

精彩评论

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