Control.UniqueID 속성

정의

서버 컨트롤에 대해 계층적으로 정규화된 고유 식별자를 가져옵니다.

public:
 virtual property System::String ^ UniqueID { System::String ^ get(); };
[System.ComponentModel.Browsable(false)]
public virtual string UniqueID { get; }
[<System.ComponentModel.Browsable(false)>]
member this.UniqueID : string
Public Overridable ReadOnly Property UniqueID As String

속성 값

String

서버 컨트롤에 대한 정규화된 식별자입니다.

특성

예제

다음 예제에서는 개체를 ArrayList 만들고 세 개의 텍스트 문자열로 채우고 웹 서버 컨트롤을 페이지가 로드될 때의 데이터에 ArrayList 바인딩 Repeater 합니다. 이 코드는 데이터 바인딩 중에 생성된 각 자식 컨트롤의 속성을 가져옵니다 UniqueID . 이 코드는 세 가지 버전의 컨트롤을 Label 생성하고 해당 UniqueID 속성 값을 페이지에 씁니다.

<script language="c#" runat="server">
    
  void Page_Load(Object sender, EventArgs e) 
  {
      StringBuilder sb = new StringBuilder();
      sb.Append("Container: " + 
          MyDataList.NamingContainer.ToString() + "<p>");

      ArrayList a = new ArrayList();
      a.Add("A");
      a.Add("B");
      a.Add("C");

      MyDataList.DataSource = a;
      MyDataList.DataBind();

      for (int i = 0; i < MyDataList.Controls.Count; i++)
      {
          Label l = 
              (Label)((RepeaterItem)MyDataList.Controls[i]).FindControl("MyLabel");
          sb.Append("Container: " + 
              ((RepeaterItem)MyDataList.Controls[i]).NamingContainer.ToString() + 
              "<p>");
          sb.Append("<b>" + l.UniqueID + "</b><p>");
      }
      ResultsLabel.Text = sb.ToString();
}
</script>
  <script language="vb" runat="server">
      
      Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
          Dim sb As New StringBuilder()
          sb.Append("Container: " + _
          MyDataList.NamingContainer.ToString() + "<p>")

          Dim a As New ArrayList()
          a.Add("A")
          a.Add("B")
          a.Add("C")

          MyDataList.DataSource = a
          MyDataList.DataBind()
    
          Dim i As Integer
          Dim l As Label
          For i = 0 To MyDataList.Controls.Count - 1
              l = CType(CType(MyDataList.Controls(i), RepeaterItem).FindControl("MyLabel"), Label)
              sb.Append("Container: " & _
                 CType(MyDataList.Controls(i), RepeaterItem).NamingContainer.ToString() & _
                 "<p>")
              sb.Append("<b>" & l.UniqueID.ToString() & "</b><p>")
          Next
          ResultsLabel.Text = sb.ToString()
      End Sub
</script>

설명

이 속성은 속성과 ID 다릅니다. 속성에는 UniqueID 서버 컨트롤의 명명 컨테이너에 대한 식별자가 포함되어 있습니다. 이 식별자는 페이지 요청이 처리될 때 자동으로 생성됩니다.

이 속성은 반복되는 데이터 바인딩 서버 컨트롤 내에 포함된 서버 컨트롤을 구분하는 데 특히 중요합니다. 반복 컨트롤(즉Repeater, ,DataList, DetailsViewFormViewGridView 서버 컨트롤 또는 데이터가 바인딩된 경우 반복 기능을 포함하는 사용자 지정 서버 컨트롤)은 자식 컨트롤의 명명 컨테이너 역할을 합니다. 즉, 해당 속성 값이 충돌하지 않도록 자식 컨트롤에 대해 고유한 네임스페이 ID 스를 만듭니다.

예를 들어 서버 컨트롤에 ASP.NET Label 웹 서버 컨트롤을 Repeater 포함하고 컨트롤 IDLabel 속성 값 및 Repeater ID MyRepeater해당 값을 MyLabel할당하는 경우입니다. If you bind data to the Repeater to an ArrayList object with three entries, the resulting UniqueID properties for each instance of the Label server controls are MyRepeater$ctl00$MyLabel, MyRepeater$ctl01$MyLabel, and MyRepeater$ctl02$MyLabel.

적용 대상

추가 정보