IWebPart.Subtitle Property

Definition

Gets a string that is concatenated with the Title property value to form a complete title for a WebPart control.

C#
public string Subtitle { get; }

Property Value

A string that serves as a subtitle for the control. The default value is an empty string ("").

Examples

The following code example demonstrates declarative and programmatic use of the Subtitle 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 Subtitle property. Note that the property is read-only and is meant to be used to provide a default subtitle that is appended to the main title of a control.

C#
public string Subtitle
{
  get
  {
    object objSubTitle = ViewState["Subtitle"];
    if (objSubTitle == null)
      return "My Subtitle";

    return (string)objSubTitle;
  }

}

The second part of the code example shows how the user control that implements the IWebPart interface is referenced in a WebPartZone control, and how the writable properties from IWebPart are set declaratively on the control. After you load the page in a browser, note that the default value of the Subtitle property, which was set in the user control's implementation code, is appended to the title in the control's title bar.

ASP.NET (C#)
<%@ 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>

Remarks

The Subtitle property is used to return a default subtitle string for a WebPart control that is appended to the control's title in the title bar.

If you provide a default value for the Subtitle property in a control that implements the IWebPart interface, the Web Parts control set automatically appends it to the value of the Title property of the control at run time.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also