什么是找到使用jQuery一个ASP.Net控制最好的方法? [英] What is best method to find a ASP.Net control using jQuery?

查看:123
本文介绍了什么是找到使用jQuery一个ASP.Net控制最好的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在实现我的第一显著使用脚本的jQuery我需要找到网页上的特定Web的控制。自从我与DotNetNuke的工作,没有保障,因为容器控件的ClientID的控制可以从现场切换到现场。我结束了使用一个属性选择器,查找,与对照的服务器ID结尾的ID。

  $(选择[ID $ ='cboPanes'])

这看起来可能不是最好的方法。是否有另一种方式来做到这一点?


@Roosteronacid - 虽然我得到我想要的控制,我尽量遵循成语对于一个给定的技术/语言。当我在C#程序,我尝试做它最需要的C#功能的优势的方式。由于这是我的第一次努力在真正使用jQuery,并且因为这将受到数千名用户10的使用,我要确保我创建code,这也是对别人的好榜样。

@toohool - 那肯定会的工作,但不幸的是我需要保持的JavaScript在单独的文件出于性能的考虑。如果内联的JavaScript,因为每个页是动态生成的,你真的不能利用缓存的非常好。我最终会一遍又一遍地发送相同的javascript到客户端再次,只是因为网页上的其他内容的修改。


@Roosteronacid - 虽然我得到我想要的控制,我尽量遵循成语对于一个给定的技术/语言。当我在C#程序,我尝试做它最需要的C#功能的优势的方式。由于这是我的第一次努力在真正使用jQuery,并且因为这将受到数千名用户10的使用,我要确保我创建code,这也是对别人的好榜样。

@toohool - 那肯定会的工作,但不幸的是我需要保持的JavaScript在单独的文件出于性能的考虑。如果内联的JavaScript,因为每个页是动态生成的,你真的不能利用缓存的非常好。我最终会一遍又一遍地发送相同的javascript到客户端再次,只是因为网页上的其他内容的修改。


解决方案

  $(#<%= cboPanes.ClientID%GT;)

这将动态注入控制的DOM ID。当然,这意味着你的JS必须在一个ASPX文件,而不是在外部JS文件

In implementing my first significant script using jquery I needed to find a specific web-control on the page. Since I work with DotNetNuke, there is no guaranteeing the controls ClientID since the container control may change from site to site. I ended up using an attribute selector that looks for an ID that ends with the control's server ID.

$("select[id$='cboPanes']")

This seems like it might not be the best method. Is there another way to do this?


@Roosteronacid - While I am getting the controls I want, I try to follow the idioms for a given technology/language. When I program in C#, I try to do it in the way that best takes advantage of C# features. As this is my first effort at really using jQuery, and since this will be used by 10's of thousands of users, I want to make sure I am creating code that is also a good example for others.

@toohool - that would definitely work, but unfortunately I need to keep the javascript in separate files for performance reasons. You can't really take advantage of caching very well if you inline the javascript since each "page" is dynamically generated. I would end up sending the same javascript to the client over and over again just because other content on the page changed.


@Roosteronacid - While I am getting the controls I want, I try to follow the idioms for a given technology/language. When I program in C#, I try to do it in the way that best takes advantage of C# features. As this is my first effort at really using jQuery, and since this will be used by 10's of thousands of users, I want to make sure I am creating code that is also a good example for others.

@toohool - that would definitely work, but unfortunately I need to keep the javascript in separate files for performance reasons. You can't really take advantage of caching very well if you inline the javascript since each "page" is dynamically generated. I would end up sending the same javascript to the client over and over again just because other content on the page changed.

解决方案

$("#<%= cboPanes.ClientID %>")

This will dynamically inject the DOM ID of the control. Of course, this means your JS has to be in an ASPX file, not in an external JS file.

这篇关于什么是找到使用jQuery一个ASP.Net控制最好的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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