IWebPart.CatalogIconImageUrl 屬性

定義

取得或設定至影像的 URL,該影像表示控制項目錄中的 WebPart 控制項。

public:
 property System::String ^ CatalogIconImageUrl { System::String ^ get(); void set(System::String ^ value); };
public string CatalogIconImageUrl { get; set; }
member this.CatalogIconImageUrl : string with get, set
Public Property CatalogIconImageUrl As String

屬性值

String

字串,表示至影像的 URL,該影像用於表示目錄中的控制項。 預設值為空字串 ("")。

範例

下列程式碼範例示範 屬性的 CatalogIconImageUrl 宣告式和程式設計用法。 此範例的完整原始程式碼位於類別概觀的 IWebPart Example 區段中。

程式碼範例的第一個部分示範使用者控制項如何實作 CatalogIconImageUrl 屬性。

public string CatalogIconImageUrl
{
  get
  {
    object objTitle = ViewState["CatalogIconImageUrl"];
    if (objTitle == null)
      return String.Empty;

    return (string)objTitle;
  }
  set
  {
    ViewState["CatalogIconImageUrl"] = value;
  }
}
Public Property CatalogIconImageUrl() As String _
  Implements IWebPart.CatalogIconImageUrl
  Get
    Dim objTitle As Object = ViewState("CatalogIconImageUrl")
    If objTitle Is Nothing Then
      Return String.Empty
    End If
    Return CStr(objTitle)
  End Get
  Set(ByVal value As String)
    ViewState("CatalogIconImageUrl") = value
  End Set
End Property

程式碼範例的第二個部分示範使用者控制項中的 方法,當使用者從頁面上的選項按鈕選取適當的屬性名稱、在文字方塊中設定新的值,然後按一下 [更新] 按鈕時,以程式設計方式設定屬性的值 CatalogIconImageUrl

重要

這個範例有一個可接受使用者輸入的文字方塊,這可能會造成安全性威脅。 根據預設,ASP.NET Web 網頁會驗證使用者輸入未包含指令碼或 HTML 項目。 如需詳細資訊,請參閱 Script Exploits Overview (指令碼攻擊概觀)。

// Update the selected IWebPart property value.
void Button1_Click(object sender, EventArgs e)
{
  String propertyValue = Server.HtmlEncode(TextBox3.Text);
  TextBox3.Text = String.Empty;

  switch (RadioButtonList1.SelectedValue)
  {
    case "title":
      this.Title = propertyValue;
      break;
    case "description":
      this.Description = propertyValue;
      break;
    case "catalogiconimageurl":
      this.CatalogIconImageUrl = propertyValue;
      break;
    case "titleiconimageurl":
      this.TitleIconImageUrl = propertyValue;
      break;
    case "titleurl":
      this.TitleUrl = propertyValue;
      break;
    default:
      break;
  }
}
' Update the selected IWebPart property value.
Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
  Dim propertyValue As String = Server.HtmlEncode(TextBox3.Text)
  TextBox3.Text = String.Empty
    
  Select Case RadioButtonList1.SelectedValue
    Case "title"
      Me.Title = propertyValue
    Case "description"
      Me.Description = propertyValue
    Case "catalogiconimageurl"
      Me.CatalogIconImageUrl = propertyValue
    Case "titleiconimageurl"
      Me.TitleIconImageUrl = propertyValue
    Case "titleurl"
      Me.TitleUrl = propertyValue
    Case Else
  End Select

End Sub 'Button1_Click

程式碼範例的第三個部分示範如何在 控制項中 WebPartZone 參考實 IWebPart 作 介面的使用者控制項,以及如何 CatalogIconImageUrl 以宣告方式在 控制項上設定 屬性。 請注意,因為此範例中未提供Web 組件控制項目錄,所以您無法看到設定此屬性的實際效果。

<%@ page language="c#" %>
<%@ register tagprefix="uc1" 
    tagname="AccountUserControlCS" 
    src="AccountUserControlcs.ascx"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>
      Personalizable User Control with IWebPart Properties
    </title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:webpartmanager id="WebPartManager1" runat="server" />
      <asp:webpartzone 
        id="zone1" 
        runat="server" 
        headertext="Main" 
        CloseVerb-Enabled="false">
        <zonetemplate>
          <uc1:AccountUserControlCS 
            runat="server" 
            id="accountwebpart" 
            title="Account Form"
            Description="Account Form with default values."
            CatalogIconImageUrl="MyCatalogIcon.gif"
            TitleIconImageUrl="MyTitleIcon.gif"
            TitleUrl="MyUrl.html"/>
        </zonetemplate>
      </asp:webpartzone>    
    </form>
  </body>
</html>
<%@ page language="VB" %>
<%@ register tagprefix="uc1" 
    tagname="AccountUserControlVB" 
    src="AccountUserControlvb.ascx"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>
      Personalizable User Control with IWebPart Properties
    </title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:webpartmanager id="WebPartManager1" runat="server" />
      <asp:webpartzone 
        id="zone1" 
        runat="server" 
        headertext="Main" 
        CloseVerb-Enabled="false">
        <zonetemplate>
          <uc1:AccountUserControlVB 
            runat="server" 
            id="accountwebpart" 
            title="Account Form"
            Description="Account Form with default values."
            CatalogIconImageUrl="MyCatalogIcon.gif"
            TitleIconImageUrl="MyTitleIcon.gif"
            TitleUrl="MyUrl.html"/>
        </zonetemplate>
      </asp:webpartzone>    
    </form>
  </body>
</html>

備註

Web 組件應用程式通常會提供目錄 (或清單,或列出使用者可以新增至頁面的控制項) 。 CatalogIconImageUrl控制項上的 屬性包含影像的 URL,代表控制項出現在目錄中時。

適用於

另請參閱