如何在用户控件中找到控件,该控件将在另一个使用JavaScript的控件中进一步使用 [英] How to find Controll within User Controll that is further used in another controll using JavaScript

查看:103
本文介绍了如何在用户控件中找到控件,该控件将在另一个使用JavaScript的控件中进一步使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个搜索控件,该控件正在其他控件中使用.我在搜索控件中有复选框.我想在使用Search Controll的Controll中访问此复选框.

我在Controll中获取Search Controll的ClientId,在其中我将Search Controll用作

We have a search controll that is being used in further controlls. I have checkbox in Search Controll. I want to access this checkbox in Controll where I am using Search Controll.

I get ClientId of search Controll in controll where I am using Search Controll as

var SearchVoucherClientId = '<%= this.ucVoucherSearch.ClientID %>';



SearchVoucherClientId是存在CheckBox的Controll的搜索ID.
现在,我将CheckBox的控件ID设为



SearchVoucherClientId is the search Id of Controll in which CheckBox is Existed.
Now I aceess the Controll Id of CheckBox as

var prefix = "_ctl";
var chkCancelled = "chkCancelled"
var chkCancelledId = SearchVoucherClientId + prefix + "_" + chkCancelled;



但是chkCancelledId变量为Null.请帮助我获取正确的CheckBox ID.

谢谢

Azhar Iqbal



But chkCancelledId variable is Null. Please Help me to get the correct ID of CheckBox.

Thanks

Azhar Iqbal

推荐答案

ASP.NET会在渲染时通过在父控件的前缀I之前修饰ID,如果使用了多个嵌套层,那么您不能只将_ctrl添加到ID中.

使用JQuery,您可以找到元素

ASP.NET will mangle the id when rendering by prefixing the parent control''s I''d, for multiple nested layers if used, so you can''t just add _ctrl to the id.

Using JQuery you could find the element


("[id


=''myControl'']")
=''myControl'']")



这将查找所有ID以我的控件结尾的元素,而不管前缀是什么



This will find any element(s) whose id ends with my control regardless of the prefix


这篇关于如何在用户控件中找到控件,该控件将在另一个使用JavaScript的控件中进一步使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆