ASP. NET Server-side controls have three ID attributes: clientid and uniqueid.
Id indicates the identifier of the server-side programming of the control.CodeYou must use this ID to program access the properties, methods, and time of the control on the server.
Clientid indicates the ID of the client control generated by the server, which is often used to access the HTML elements displayed by the server control in the client script. 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.
Uniqueid is used to obtain the unique identifier of a server control in hierarchical mode. 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.
Obtain the Server Control identifier generated by ASP. NET.
Problem 1: The Control ID of Asp.net must be used in the page JavaScript of the user control.
Problem 2: The Asp.net Control ID must be used in the subpage JavaScript of the master page.
Solution:
Document. getelementbyidx ("<% = textbox1.clientid %>"). value = "1234567 ";
This code can be used to access server-side controls on the client. Because ASP. NET generates different names for rendering server-side controls on the client, this function is useful.
Note: The Asp.net controls are static controls (controls added by tools)
Question 3: How to obtain the clientid of the dynamically created control exists: you cannot use "<% = textbox1.clientid %>" on the page ". method (the method is not available because the control is dynamically created), and textbox1.clientid cannot be used in the page script (the obtained ID is incorrect ).
Solution:
(CityspecproductscheduledControl. ascx. CS code snippet)
Textbox text = new Textbox ();
Text. maxlength = 12;
Text. Columns = 12;
Text. Text = datetime. Now. tow.datestring ();
Text. ID = "dateid ";
Text. Attributes. Add ("onclick", "calendar ()");
Text. Attributes. Add ("class", "text ");
htmlimage dateimg = new htmlimage ();
dateimg. src = ".. /commonimages/cal.gif ";
string JS = string. format ("calendar ({0 }_{ 1})", this. clientid, text. clientid); // key code, which is manually generated according to the generation rules of client clientid.
dateimg. Attributes. Add ("onclick", JS);