the difference between ClientID and ID of web control

王朝asp·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

Basically, The ID of web control should be used on server

programming, and the ClientID should be used on Client, pretty basic.

if you want to use the ID of web control on Client, you will find it

doesn't work, because ASP.NET will not set it down to Client.

and the ID maybe is not unique in a page, a simplest example is:

1. create a web form and a web user control.

2. create a button on the web user control, it's ID should be Button1.

3. create a button on the web form, it's ID should be Button1 too.

4. put the web user control on the web form, now, in this web form, we have two buttons which name are both "Button1".

when we are programming on the server, I can use the Button1 to

identify the button in web form and web user control both because they

are in different scenario.

But when in client, there's only one page, right? so ASP.NET will generate ClientID automatically so that they are different. If you view the source of the final page in web brower, you can find the Button in web user control's id property changed(I think it's exactly ClientID, not the ID what we discuss here) to WebUserControl1_Button1(in my project, maybe different in your project, but the key is that it has been changed.)

let me summarize where we are, the ID and ClientID of web control are different, ClientID unique in a web page, but ID not, because the "web page" is a Client term, right? when we are programming on server, we concentrate over web form, web control, commonly not web page. so if we want to operate control on client, for example: register a script to page using Register..... function to operate control on client, we should inject control's ClientID into script, not the ID.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航