WebPartDescription.ID 屬性

定義

取得相對應 WebPart 控制項的 ID。

public:
 property System::String ^ ID { System::String ^ get(); };
public string ID { get; }
member this.ID : string
Public ReadOnly Property ID As String

屬性值

String

字串,包含控制項的 ID。

範例

下列程式碼範例示範屬性的程式 ID 設計用法。 如需執行此程式碼範例所需的完整程式碼,請參閱類別概觀主題的 WebPartDescription 範例一節。

網頁方法中的 Button1_Click 下列程式碼示範如何使用 方法來取得目錄中 GetAvailableWebPartDescriptions 的物件集合 WebPartDescription ,然後迴圈查看 物件,以顯示目錄中 WebPartDescription 每個 WebPart 控制項的詳細資料。 請注意, ID 屬性值會在下列程式碼中擷取。

protected void Button1_Click(object sender, EventArgs e)
{
  Label1.Text = String.Empty;
  
  WebPartDescriptionCollection descriptions = 
    DeclarativeCatalogPart1.GetAvailableWebPartDescriptions();

  foreach (WebPartDescription desc in descriptions)
  {
    Label1.Text += "ID: " + desc.ID + "<br />" +
      "Title: " + desc.Title + "<br />" +
      "Description: " + desc.Description + "<br />" +
      "ImageUrl: " + desc.CatalogIconImageUrl + "<br />" +
      "<hr />";
  }
}
Protected Sub Button1_Click(ByVal sender As Object, _
  ByVal e As System.EventArgs)
  
  Label1.Text = String.Empty
      
  Dim descriptions As WebPartDescriptionCollection = _
   DeclarativeCatalogPart1.GetAvailableWebPartDescriptions()
          
  Dim desc As WebPartDescription
      
  For Each desc In descriptions
    Label1.Text += "ID: " & desc.ID & "<br />" & _
      "Title: " & desc.Title & "<br />" & _
      "Description: " & desc.Description & "<br />" & _
      "ImageUrl: " & desc.CatalogIconImageUrl & "<br />" & _
      "<hr />"
  Next
  
End Sub

備註

屬性的值 ID 不能是 null ;它必須一律有值。 屬性 ID 會直接對應至 Control.ID 屬性。

只有在 ID 頁面處於目錄顯示模式,且 WebPart 控制項顯示在控制項目錄時,屬性才會套用。

適用於

另請參閱