Export (0) Print
Expand All

IWebPart.CatalogIconImageUrl Property

Gets or sets the URL to an image that represents a WebPart control in a catalog of controls.

Namespace:  System.Web.UI.WebControls.WebParts
Assembly:  System.Web (in System.Web.dll)

string CatalogIconImageUrl { get; set; }

Property Value

Type: System.String
A string that represents the URL to an image used to represent the control in a catalog. The default value is an empty string ("").

Web Parts applications often provide a catalog (or list) of controls that users can add to a page. The CatalogIconImageUrl property on a control contains the URL to an image that represents the control when it appears in a catalog.

The following code example demonstrates declarative and programmatic use of the CatalogIconImageUrl property. The complete source code for the example is found in the Example section of the IWebPart class overview.

The first part of the code example shows how the user control implements the CatalogIconImageUrl property.

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

    return (string)objTitle;
  }
  set
  {
    ViewState["CatalogIconImageUrl"] = value;
  }
}

The second part of the code example demonstrates the method in the user control that programmatically sets the value of the CatalogIconImageUrl property when a user selects the appropriate property name from the radio buttons on the page, sets a new value in the text box, and then clicks the Update button.

Security noteSecurity Note

This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see 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;
  }
}

The third part of the code example shows how the user control that implements the IWebPart interface is referenced in a WebPartZone control, and how the CatalogIconImageUrl property is set declaratively on the control. Note that because there is no catalog of Web Parts controls provided with this example, you cannot see the actual effect of setting this property.

<%@ 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>

.NET Framework

Supported in: 4.5.3, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft