ASP. NET control attributes: ID, clientid, and uniqueid

Source: Internet
Author: User

IDIndicatesServer programming identifierWe need to use this ID to write the server-side code. This ID can be used to program access to the properties and methods of the server-side controls on the server side.

ClientidIndicatesClient Control IDIt is often used to access the HTML elements rendered by the server control in client scripts. Generally, it is the same as the server ID. Sometimes, a unique name cannot be generated for the control. For example, if a repeater space contains a label control in a template, multiple HTML elements of the lable are generated on the client. To prevent name conflicts, Asp. net generates a unique clientid for each server control. clientid is generated by connecting the uniqueid value of the parent control of the Child control with the ID value of the control.
When it comes to clientid, by the way, onclientclick is mainly a client event for buttons executed on the client.
If the onclientclick event is set to false, the system only executes the onclientclick event and does not touch the onclick event on the server.
Example:
When using user controls, we usually need to verify the validity and validity of data. If it is on a common page, we can solve this problem easily by using JavaScript, but if it is used the user control has a problem that the Control ID on the server is unknown !! We have a solution !!

Code
1 <asp: button id = "btnsave" runat = "server" text = "save" cssclass = "button"  
2 onclick = "btnsave_click" onclientclick = "Return isnull ();"/> & nbsp ;&
Nbsp;
3 <script language = "JavaScript" type = "text/JavaScript">

4 Function isnull ()
5
{
6 var txtid = '<% = this.txt code. clientid %>'
;
7 var TXT =
Document. getelementbyid (txtid). value;
8 If (txt = ""
)
9
{
10 alert ("Enter the editing code"
)
11 return false
;
12}

13}
14
15 </SCRIPT>

The above code can solve this problem !!
<% = This.txt code. clientid %> boundTxtcode. clientid
Verify the content through the onclientclick event. If the data is unqualified, false is returned. The button only respondsOnclientclickEvent and onclick will not be executed !! At this time, dragging the user control to the page can verify the validity of the data as well as on this page.

Uniqueid

Used to obtainUnique, hierarchical identifier of a server control. When you place controls in repeated controls (repeater, datalist, and DataGrid), multiple server-side controls may be generated, which requires distinguishing the various controls on the server, so that their ID attributes do not conflict. Uniqueid is generated by connecting the uniqueid value of the parent control of the Child control with the ID value of the control. Each part is connected by the character specified by the idseparator attribute. By default, the idseparator attribute is a colon character (:). This attribute is newly added in. Net framework2.0.

Clientid and uniqueid are the identifiers used to distinguish the client and server of the control when the control is placed in the repeater, datalist, and DataGrid. Id indicates the general programming identifier of the control on the server when the control is not repeated.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.