[英]user controls in asp.net prefixing string to child controls causing problem to refer them in javascript
I have user control in which there are text boxes no i am using the AJAX to populate the child controls dynamically however asp.net appending some string to child controls causing problems to write the JavaScript code. 我有用户控件,其中没有文本框,我使用AJAX动态填充子控件,但是asp.net在子控件中附加了一些字符串,导致编写JavaScript代码时出现问题。
Though i have tried getElementLike('key') which iterate elements and get the right one for me but this is really inefficient. 尽管我尝试过getElementLike('key'),它会迭代元素并为我获取合适的元素,但这确实效率不高。 So if anybody has any insight on this issue please provide you input/suggestions.
因此,如果有人对此问题有任何见解,请提供您的意见/建议。
Thanks all, 谢谢大家
You will need to refer to those controls like this: 您将需要引用如下控件:
// typical way
var element1 = document.getElementById("<%= control.ClientID %>");
// jquery way
var element2 = $("#<%= control.ClientID %>");
Look at using someControl.ClientId
, which will give you the ASP.NET generated id of the control. 看一下使用
someControl.ClientId
,它将为您提供ASP.NET生成的控件ID。 Using this Id you will be able to correctly target the element via javascript. 使用此ID,您将能够通过javascript正确定位元素。
使用jquery使用$("[id$='CWRCompanyId']")
类的东西来选择项目,这基本上是在寻找以您期望的ID结尾的ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.