选择元素使用JavaScript一个UserControl [英] Selecting elements in a usercontrol using JavaScript

查看:103
本文介绍了选择元素使用JavaScript一个UserControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含用户控件的Web表单,我希望能够从表单中使用JavaScript的用户控件内访问HTML元素。

I have a web form that contains a usercontrol and I would like to be able to access the html elements within the usercontrol from the form page using javascript.

我试过如下:

document.getElementById('<%= usercontrol.clientid %>')

不过这回

我身边有一个外观与萤火,发现在该用户的标签像usercontrolid_myelement的ClientID渲染。我猜测,这样的事情可能工作:

I had a look around with firebug and found that the tags in the usercontrol render with clientids like usercontrolid_myelement. I'm guessing that something like this might work:

document.getElementById('<%= usercontrol.clientid %>'+'_myelement')

是否有这样做的更好的/更好的方式?

Is there a better/nicer way of doing this?

推荐答案

我已通过您的问题见过我的精神力量!

I have seen through your question with my psychic powers!

您的问题是,你在你的主页serverscript无法访问您的用户控件的ASP.net元素。

Your problem is that your serverscript in your main page can't access the ASP.net elements of your usercontrol.

的解决方案是,以暴露元素,或者你需要的元素,通过在该用户属性的仅仅的ClientID。然后像你愿意,你可以在JavaScript中使用的ClientID。

The solution is to expose the elements, or just the ClientIDs of the elements you need, through properties in the usercontrol. Then you can use the ClientIDs in Javascript like you want to.

这篇关于选择元素使用JavaScript一个UserControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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