QQ:1187362408 welcomes technical exchanges and learning
Id,clientid,uniqueid and ClientIDMode Properties for ASP. 4.0 (Id,clientid,uniqueid and ClientIDMode properties):
Todo:
1,id:id Yes ([1]
ID is the design of the time you specify the ID, is the programming identifier we assign to the server control, we often use This.controlid to find the control, then this controlid is the ID mentioned here
)
2,uniqueid: ([2]
UniqueID a unique, hierarchical, form-qualified identifier for a server control. is used when you need to participate in the service-side callbacks. When you place controls in a repeating control (Repeater, DataList, and DataGrid), it is possible to generate multiple server-side controls, which requires differentiating the individual controls on the server side so that their ID properties do not conflict. UniqueID is generated by connecting the UniqueID value of the child control's parent control to the control's ID value, and the individual parts are concatenated with the characters specified by the Idseparator property. By default, the Idseparator property is a colon character (:). This property is a new addition to the. Net Framework2.0. (UniqueID's explanation makes reference, this article emphasizes the ID and ClientID
)
3,clientid: ([3]
Sometimes, you cannot assign a unique name to a control. For example, if the Repeater control contains a label control in one of its templates, an instance of the label control is rendered for each item in the Repeater control. When rendering multiple instances of a control, to prevent naming conflicts, ASP. NET automatically generates a unique ClientID value for each server control on the page. The ClientID value is generated by connecting the control's ID value and the UniqueID value of its parent control. If the ID value of the control is not specified, the automatically generated value is used. The individual parts of the generated ID are delimited by the underscore character (_).
)
4,clientidmode: ([4]
There is a property called ClientIDMode on each of the controls in ASP. NET 4.0, which solves the difficulty of getting the control ID above. There are four optional values for this property, which can control the ID format of the generated control on the page, depending on the selected value.
Let's take a look at the four values of the ClientIDMode property below:
1,autoid:[5]
When the control's ClientIDMode is selected as Autoid, the control's ClientID value is concatenated by concatenating each ancestor container control (such as the GridView, ListView, LoginView is the ID of the container control, and the ID of the parent container control and its own ID value are generated, of course, if the control is not in any container control whose ClientID value is its own ID value, no change will be made. Also, if the control's parent container control or ancestor container control is a container control that displays multiple rows of data, such as a GridView, a ListView, or a container control that displays multiple rows of data, an incremented line number format will be inserted after the container control's ID value. The following underscore characters (_) are separated between the sections. It is visible that the autoid scheme was used in versions prior to ASP. NET 4 to generate the ClientID value of the control.
For example, the following GridView inside there is a name Label1 ID, we will Label1 ClientIDMode set to Autoid:
<span style= "color: #000000;" >code highlighting produced by Actipro Codehighlighter (freeware) http://www. Codehighlighter.com/--><asp:gridview id= "Grd_account" runat= "Server" allowpaging= "True" autogeneratecolumns= "False" datakeynames= "account Number" datasourceid= "Sds_account" height= "63px" width= "676px" pagesize= "5" ClientID Mode= "Autoid" > <Columns> <asp:templatefield headertext= "account number" sortexpression= "account Num ber "> <ItemTemplate> <asp:label id=" Label1 "runat=" Server "text=" <%# Bind ("[Account number]")%> ' clientidmode= "autoid" ></asp:Label> </ItemTemplate> </asp:TemplateField> </columns></asp:gridview>html:code highlighting produced by Actipro Codehighlighter (freeware) http://www. Codehighlighter.com/--><table cellspacing= "0" rules= "All" border= "1" id= "Grd_account" style= "HEIGHT:63PX; Width:676px;border-collapSe:collapse; " > <tr> <th scope= "col" >account number</th> </tr> <tr> <td> <span id= "Grd_account_ctl02_label1" >1060</span> </td> </tr> <tr> <td> <span id= "Grd_account_ctl03_label1" >1200</span> </td> </tr> <tr> <td> <span id= "Grd_account_ctl04_label1" >1510</span> </td> </tr></table></span>
2,static:[6]
When the control's ClientIDMode is selected as static, the control's ClientID value is the ID property value set by itself, and its ClientID value is not affected by the parent container control.
For example, we modify the above code slightly to change the ClientIDMode property of Label1 to static:
<span style= "color: #000000;" ><asp:gridview id= "Grd_account" runat= "Server" allowpaging= "True" autogeneratecolumns= "False" datakeynames= " Account Number "datasourceid=" Sds_account "height=" 63px "width=" 676px "pagesize=" 5 "> <Columns> &L T;asp:templatefield headertext= "account number" sortexpression= "account Number" > <ItemTemplate> <asp:label id= "Label1" runat= "server" text= ' <%# Bind ("[Account number]")%> ' clientidmode= ' Static ' >&L t;/asp:label> </ItemTemplate> </asp:TemplateField> </Columns>< /asp:gridview>html:<table cellspacing= "0" rules= "All" border= "1" id= "Grd_account" style= "height:63px;width : 676px;border-collapse:collapse; " > <tr> <th scope= "col" >account number</th> </tr><tr> <td> <span id= "Label1" >1060</span> </td> </tr><tr> <td> <span id= "Label1" >1200</span> </td> </tr><tr> <td> <span id= "Label1" >1510</span> </td> </TR></TABLE></SPAN&G T
3,inherit: [7]
This property has nothing to say, if the control's ClientIDMode is checked for inherit, then the clientidmode of the control will use the ClientIDMode value of the parent container control. If the clientidmode of the parent container control is also inherit, the ClientIDMode value of the upper container control is used until it is traced back to the ClientIDMode value of the page. The ClientIDMode value of the page defaults to predictable, and you can make changes to the value in the <%@ page%> directive on the page. Also inherit is the default value for the ClientIDMode property of all controls in ASP. NET 4.0.
4,predictable:[8]
First I explained that the reason for the last write predictable, because I found that the control clientidmode is predictable when the mechanism of generating clientid is very complex, to be divided into several parts of the discussion, there are special cases, So I can only say that as far as possible I found the predictable generated clientid mechanism elaborated clearly.
When the clientidmode of a control is selected as predictable, the ClientID value of the control is generated by concatenating the ClientID values of the parent container control (such as the GridView, ListView, LoginView, and so on, which are container controls). In addition, if the control is in a parent container control or ancestor container control that displays multiple rows of data, such as a GridView, a ListView, or a container control that displays multiple rows of data, the control is also added at the end of the ClientID value of the controls Clientidrowsuffix The value of the data field specified in the property. For the GridView control, the Clientidrowsuffix property can specify multiple data fields. If the Clientidrowsuffix property is blank, the increment line number is added at the end, not the data field value. The following underscore characters (_) are separated between the sections.
That's what MSDN says, but after experimenting, I've found that predictable's features should be expressed in such a way:
inherit[+ "_" +clientidrowsuffix]
This means that if the clientidmode of a control is selected as predictable, When ASP. NET generates the control's ClientID, it first looks at what the clientidmode of the parent container control the control belongs to, and then builds the clientid of the control itself with the ClientIDMode rule of the control's parent container control, and finally if the control belongs to the parent container control or ancestor A container control is a container control that displays multiple rows of data, and a suffix string is appended to the ClientID that the control has generated, based on the value of the Clientidrowsuffix property of the parent container control or ancestor container control.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Id,clientid,uniqueid and ClientIDMode attribute articles for ASP. NET 4.0