C#asp.net为什么会出现的ClientID和UniqueID的有区别吗? [英] C# asp.net Why is there a difference between ClientID and UniqueID?

查看:276
本文介绍了C#asp.net为什么会出现的ClientID和UniqueID的有区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道客户端ID用于javascript和唯一ID的服务器端和客户端ID使用一个下划线(_)和唯一ID在asp.net 2.0使用一个美元符号($)。但我不明白的是为什么要用两个不同的ID。为什么不能公正或使用下划线或使用两个美元符号:服务器和客户端。有人能解释一下吗?

I know ClientID is used for javascript and UniqueId for server side and that ClientID uses an underscore (_) and UniqueId uses a dollar sign ($) in asp.net 2.0. But what I don't get is why use two different id's. Why isn't possible to just OR use the underscore OR use the dollar sign in both: server and client side. Can someone explain this?

推荐答案

(除了我原来的答复以上)

嗯,正如你可能知道的UniqueID用于与name属性和客户端Id与呈现的HTML标签的id属性。 UniqueID的使用冒号作为分隔符。在另一方面的clientid使用下划线作为分隔符,因为结肠是不是在JavaScript中的变量名允许的。客户端ID确实也是页面上独一无二的,因为UniqueID的是,但ClientID的是在客户端处理和UniqueID的针对服务器端(pretty明显),后者尤其是为回发数据和事件复合控件的路线

Well, as you probably know UniqueID is used with name attribute and ClientId with id attribute of rendered HTML tag. UniqueID uses colon as separator. On the other hand ClientId uses underscore as separator, because colon is not allowed in JavaScript variable names. ClientID is indeed also unique on the Page as UniqueID is, but ClientID is targeted at client-side processing and UniqueID for server-side (pretty obvious),the latter especially to route for postback data and events with composite controls

不过我觉得有些道理可能是使用下划线作为正常对照ID的分隔符是pretty共同的行为,因此强调不能在UniqueID的作为控制分离使用(如果我们想从理论上认为有一个属性管理),因为你不能让控件之间的区别。在另一方面对于同样的道理,你不能在控制标识使用冒号,页面框架不允许它,所以它可以确保冒号不能获取到的ClientID(这是因为JavaScript代码不喜欢)

However I think some reasoning might be that using underscore as separator in normal Control IDs is pretty common behavior and therefore underscore cannot be used in UniqueID as control separator (if we'd theoretically think managing with one property), because you couldn't make distinction between controls. On the other hand for the same reasoning, you can't use colon in Control IDs, Page Framework does not allow it, so that it makes sure colons can't get to the ClientIDs (this was because of JavaScript does not like it).

和基于这些原因,结肠癌是在的UniqueID要使用pretty很好的选择,因为FindControl方法可以用它来导航控制树和定位控制(它可以很容易分裂的UniqueID)

And for these reasons, colon is pretty good choice to be used in UniqueID, because FindControl method can use it to navigate Control tree and locate controls (it can easily split the UniqueID).

这篇关于C#asp.net为什么会出现的ClientID和UniqueID的有区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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