. Net 4.0 Control Server Control Client ID

Source: Internet
Author: User

Client ID: The developer can now manage the Control ID that affects the displayed Client ID. The control class now provides a new clientidmode attribute, which can be used to specify the runtime behavior when determining whether to refactor the Client ID during rendering. This will delete the previous useless information in the Client ID.

Modifying the Client ID attribute ensures that each element is uniquely identified. However, this can cause a lot of trouble for developers who need to execute client script tasks. If you have used ASP. NET, you must have encountered this problem. The problem is that you do not know what the client ID is before running, so it is difficult to execute any client script task. In addition, changing pages and adding or deleting controls will generate different client IDs.

If you have used ASP. NET, you should know the skills to solve this problem. Each control has a read-only clientid attribute, which is used to provide a unique client ID. You can use it when adding a script dynamically, or more commonly, use inlineCode(Early ASP style) provides this value to the client script.

Javascript

<SCRIPT type = "text/JavaScript">

Function dosomething (){

Alert ('<% = control. clientid %> ');

}

</SCRIPT>

To solve this problem, ASP. NET 4.0 provides four clientid "modes" to meet all user needs from existing behaviors to full control. Modify the Control ID attribute in clientidmode and use it as the client ID.

The four modes are as follows:

• Legacy: This mode is used by default if clientidmode is not set for the control hierarchy. This causes the Client ID to behave in the 2.0 version framework (3.0 and 3.5 do not modify this code path ). In this mode, an ID similar to "ctl00_masterpagebody_ctl01_textbox1" is generated.

• Inheritance: This is the default action of all controls. Obtain the clientidmode value in the parent control. You do not need to set this mode for each control because it is the default. Use clientidmode only when the clientidmode is modified and the new expected behavior is to inherit the parent control.

• Static: the behavior of this mode is exactly the same as that of its name; it sets the Client ID to static. This indicates that your settings for this ID will be reflected on the Client ID. Note that this means that if static clientidmode is used in the repeat control, the developer is responsible for ensuring the uniqueness of the Client ID.

• Predictable: This mode is used when you need to ensure the uniqueness of the Framework in a predictable way. This mode is most often used for data binding controls. The framework traverses the control hierarchy and adds the parent Control ID as the prefix for the provided id until it reaches the control whose clientidmode is static in the hierarchy. When the control is located in the data binding control, a value that identifies the instance is added to the provided ID as the suffix. The clientidrowsuffix attribute is used to control the value that will be used as the suffix. This mode generates an ID similar to "gridview1_label1_0.

 

 

From msdn

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.