Control.UniqueID プロパティ
定義
階層構造で修飾されたサーバー コントロールの一意の ID を取得します。Gets the unique, hierarchically qualified identifier for the server control.
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
プロパティ値
サーバー コントロールの完全修飾 ID。The fully qualified identifier for the server control.
- 属性
例
次の例では、オブジェクトを作成 ArrayList し、3つのテキスト文字列を設定し Repeater ます。次に、 ArrayList ページが読み込まれるときに、Web サーバーコントロールを内のデータにバインドします。The following example creates an ArrayList object and populates it with three text strings, then binds a Repeater Web server control to the data in the ArrayList when the page is loaded. このコードは、 UniqueID データバインディング中に生成された各子コントロールのプロパティを取得します。The code gets the UniqueID property for each child control generated during data binding. このコードは、3つのバージョンのコントロールを生成 Label し、その UniqueID
プロパティ値をページに書き込みます。The code generates three versions of the Label control and writes their UniqueID
property values to the page.
<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 サーバーコントロールの名前付けコンテナーの識別子が含まれている点で、プロパティとは異なります。This property differs from the ID property, in that the UniqueID property includes the identifier for the server control's naming container. この識別子は、ページ要求が処理されるときに自動的に生成されます。This identifier is generated automatically when a page request is processed.
このプロパティは、繰り返されるデータバインディングサーバーコントロール内に含まれるサーバーコントロールを区別するために特に重要です。This property is particularly important in differentiating server controls contained within a data-binding server control that repeats. 繰り返しコントロール (、、、 Repeater 、 DataList DetailsView FormView および GridView Web サーバーコントロール) (または、データバインド時に繰り返し機能を含む、作成するカスタムサーバーコントロール) は、子コントロールの名前付けコンテナーとして機能します。The repeating control, which are Repeater, DataList, DetailsView, FormView, and GridView Web server controls (or any custom server controls that you create that include repeating functionality when data bound), serves as the naming container for its child controls. これは、その子コントロールに対して一意の名前空間を作成し、そのプロパティ値が競合しないようにすることを意味 ID します。This means that it creates a unique namespace for its child controls so that their ID property values do not conflict.
たとえば、ASP.NET Label Web サーバーコントロールをサーバーコントロールに含め、 Repeater Label コントロールに ID のプロパティ値 MyLabel
Repeater ID MyRepeater
としてを割り当てる場合は。For example, if you include an ASP.NET Label Web server control in a Repeater server control, and assign the Label control an ID property value of MyLabel
, and the Repeater an ID of MyRepeater
. 3つのエントリを持つオブジェクトにデータをバインドする場合、 Repeater ArrayList UniqueID サーバーコントロールの各インスタンスに対して生成されるプロパティ Label は、、 MyRepeater$ctl00$MyLabel
MyRepeater$ctl01$MyLabel
および MyRepeater$ctl02$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
.