ASPX页面中的用户控件 [英] User control in aspx page

查看:73
本文介绍了ASPX页面中的用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想将用户控件(ascx)的ID存储在javascript文件中
这样我以后可以在aspx页面中检索该ID


i want to store the id of a user controls(ascx) in javascript file
so that i can retrieve that id in aspx page at later stage

how can i do that>?

推荐答案

<script>

var id = <%=myControl.ClientId%>

</script>



但是,这不是一个好方法.为什么不让您的js函数将ID作为参数?然后在后面的代码中添加事件并在其中使用ClintID.



However, this is not a nice technique. Why not have your js function take the ID as a parameter? Then in the codebehind add your event and use the ClintID there.


构建表单时,必须为该页面唯一的用户控件分配一个ID.该id标签是您在后面的代码中使用的代码,用于从代码访问用户控件.客户端ID仅在您希望从javascript以某种方式操纵控件时才在客户端有用.唯一需要注意的是,如果您使用的是Gridview之类的控件.在这种情况下,您可以循环浏览后面代码中的每个项目,然后拉出模板中可能存在的单独的名称控件.同样,这将由id而不是客户端id来完成,因此在后面的代码中知道客户端id确实没有任何目的.如果有我缺席的正当理由,请更新问题以解释您为什么需要它.
When you build your form, you have to assign an id to the user control that is unique to the page. That id tag is what you use in the code behind to access the user control from code. The client id is only useful on the client side if you wish to manipulate the control in some way from javascript. The only caveat on this is if you are using a control like a Gridview. In those cases you can loop through each of the items from the code behind and then pull out the individually names controls that may exist in your templates. This again would be done by id and not client id so there really should be no purpose for you knowing the client id in the code behind. If there is a valid reason that I am missing, please update the question to explain why you need it.


这篇关于ASPX页面中的用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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