|
Legacy Mode 예재
Legacy mode is pretty straight forward, it generates a client side ID the way that it had in version 2.0 of the framework.
markup:
(Legacy 모드는 매우 직설적입니다. 이는 asp.net 2.0 에서 사용했던 client 단 ID 처럼 generate 합니다.)
출력 :
<input id="ctl00_MasterPageBody_ctl00_txtEcho" style="width: 65%"
name="ctl00$MasterPageBody$ctl00$txtEcho" />
Static Mode 예재
Static is the most basic of all ClientIDMode modes, what you give for the ID is what you get for the client side ID. Once again a warning that if a static ClientIDMode is used inside of a repeated control it is the developer’s responsibility to ensure client side ID uniqueness.
Static 는 모든 ClientIDMode 모드에서 제일 간단합니다. 본인이 작성한 컨트롤 ID 와 client 단 ID 가 동일하다는 것입니다.
만약 static ClientIDMode 가 반복된 컨트롤 내부에 사용이 된다면 다시 한번 경고로 알려줍니다. 이는 client 단 ID 의 고유함을 보장하기 위해 개발자에게 알려주는 것입니다.
markup:
<asp:TextBox ID="txtEcho2" runat="server" Width="65%" ClientIDMode="Static" />
<input id="txtEcho2" style="width: 65%" name="ctl00$MasterPageBody$ctl00$txtEcho2" />
Predictable Mode 예제
Predictable mode really tackles the heart of the problem. The framework previously generated it’s unique IDs to prevent ID collisions and the most common place for these types of collisions are inside databound controls. Predictable mode is really designed to work with databound controls but does not have to. There is three ways to uses the predictable mode, each one of these is defined through the ClientIDRowSuffix property that specifies the suffix for each instance. The ClientIDRowSuffix uses values from the control’s datakeys collection, so if the control does not have a datakeys collection this property is not viable. If this property is not set or is not available the row index will be used in it’s place.
1. With no ClientIDRowSuffix defined, this is also the behavior for databound controls without a datakeys collection e.g. Repeater Control. Notice that the framework has traversed the control hierarchy and prefixed the ID with the parent’s ID and suffixed the ID with row index.
markup:
<asp:GridView ID="EmployeesNoSuffix" runat="server" AutoGenerateColumns="false"
ClientIDMode="Predictable" > <Columns> <asp:TemplateField HeaderText="ID"> <ItemTemplate> <asp:Label ID="EmployeeID" runat="server" Text='<%# Eval("ID") %>' /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Name"> <ItemTemplate> <asp:Label ID="EmployeeName" runat="server" Text='<%# Eval("Name") %>' /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
<table id="EmployeesNoSuffix" style="border-collapse: collapse" cellspacing="0" rules="all" border="1"> <tbody> <tr> <th scope="col">ID</th> <th scope="col">Name</th> </tr> <tr> <td><span id="EmployeesNoSuffix_EmployeeID_0">1</span></td> <td><span id="EmployeesNoSuffix_EmployeeName_0">EmployeeName1</span></td> </tr> ... <tr> <td><span id="EmployeesNoSuffix_EmployeeID_8">9</span></td> <td><span id="EmployeesNoSuffix_EmployeeName_8">EmployeeName9</span></td> </tr> </tbody> </table>
2. With a ClientIDRowSuffix defined, this looks in the control’s datakeys collection for the value and then suffixes the ID with that value.
markup:
<asp:GridView ID="EmployeesSuffix" runat="server" AutoGenerateColumns="false"
ClientIDMode="Predictable" ClientIDRowSuffix="ID" > <Columns> <asp:TemplateField HeaderText="ID"> <ItemTemplate> <asp:Label ID="EmployeeID" runat="server" Text='<%# Eval("ID") %>' /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Name"> <ItemTemplate> <asp:Label ID="EmployeeName" runat="server" Text='<%# Eval("Name") %>' /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
출력:
<table id="EmployeesSuffix" style="border-collapse: collapse" cellspacing="0" rules="all" border="1"> <tbody> <tr> <th scope="col">ID</th> <th scope="col">Name</th> </tr> <tr> <td><span id="EmployeesSuffix_EmployeeID_1">1</span></td> <td><span id="EmployeesSuffix_EmployeeName_1">EmployeeName1</span></td> </tr> ... <tr> <td><span id="EmployeesSuffix_EmployeeID_9">9</span></td> <td><span id="EmployeesSuffix_EmployeeName_9">EmployeeName9</span></td> </tr> </tbody> </table>
3. With a ClientIDRowSuffix defined, but instead of just one value a compound value will be used. Exhibits the same behavior as one value but it will suffix both values onto the ID.
markup:
<asp:GridView ID="EmployeesCompSuffix" runat="server" AutoGenerateColumns="false"
ClientIDMode="Predictable" ClientIDRowSuffix="ID, Name" > <Columns> <asp:TemplateField HeaderText="ID"> <ItemTemplate> <asp:Label ID="EmployeeID" runat="server" Text='<%# Eval("ID") %>' /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Name"> <ItemTemplate> <asp:Label ID="EmployeeName" runat="server" Text='<%# Eval("Name") %>' /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
출력:
<table id="EmployeesCompSuffix" style="border-collapse: collapse" cellspacing="0" rules="all" border="1"> <tbody> <tr> <th scope="col">ID</th> <th scope="col">Name</th> </tr> <tr> <td><span id="EmployeesCompSuffix_EmployeeID_1_EmployeeName1">1</span></td> <td><span id="EmployeesCompSuffix_EmployeeName_1_EmployeeName1">EmployeeName1</span></td> </tr> ... <tr> <td><span id="EmployeesCompSuffix_EmployeeID_9_EmployeeName9">9</span></td> <td><span id="EmployeesCompSuffix_EmployeeName_9_EmployeeName9">EmployeeName9</span></td> </tr> </tbody> </table>
The ability to fully control the client side IDs that are generated by the framework is a request that has not generated much noise but everyone seems to want it when you mention it. We believe that we have found a good solution to the request and think that it adds some much need functionality for developer that use lots of client side scripting. There is an early preview and a walk through of this feature in CTP build that we released at PDC 2008. For more information and a much more detailed description of this feature read Scott Galloway’s blog post.
framework 에서 generate 된 Client 단 ID 들의 완벽한 컨트롤이 가능해져서 더 이상의 많은 불편사항이 없어질것입니다.
그리고 개발자의 요청사항에 대해 좋은 해결안을 찾아줄거라 믿고, 많은 client 단의 스크립팅을 사용하는 개발자분들에게 많은 함수들을 추가해 줄거라 생각이 듭니다. 이 기능은 PDC 2008 에서 릴리즈했던 CTP build 에서 나온 새로운 기능입니다.
참고로 Scott Galloway’s blog post. 에 가면, 더 상세한 설명과 기능들에 대해 알려줄겁니다.
http://weblogs.asp.net/asptest/archive/2009/01/06/asp-net-4-0-clientid-overview.aspx
번역 : 심재운 (shimpark@gmail.com)
첫댓글 역시 나오길 바랫느네 나왔군요. 쩝 그리드도 그냥 똑같은 id로 뿌려주지.. 어차피 자바스크립에서 엘러먼트바이아이디로 알아오기때문에 갯수 샐수 있는데..ㅋ 하긴 같은 아이디면 cs단에서 체크하기 어렵겟지요^^
해석 감사요~!