WebPart.Subtitle Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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

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

public virtual string Subtitle { get; }

Property Value

Type: System.String

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

Use the Subtitle property optionally to return a standard subtitle string in your custom WebPart control that will be appended to the control's title.

If you provide a value for the Subtitle property in a custom WebPart control, the Web Parts control set automatically appends it to the value of the Title property to create a complete title for the control.

The value of this property, when set, can be saved automatically to a resource file by using a designer tool. For more information, see LocalizableAttribute and ASP.NET Globalization and Localization.

Notes to Inheritors:

To supply a subtitle for instances of a custom WebPart control, you must override the Subtitle property.

The following code example demonstrates how to provide a subtitle for instances of a custom WebPart control.

The first part of this example contains the code for a custom control named TextDisplayWebPart. This control is the same as the custom control which is found in the Example section of the WebPart class overview, except that it also overrides the Subtitle property to provide a standard subtitle containing a fictitious company name for instances of the custom control. For the code example to run, you must compile this source code. You can compile it explicitly and put the resulting assembly in your Web site's Bin folder or the global assembly cache. Alternatively, you can put the source code in your site's App_Code folder, where it will be dynamically compiled at run time. This code example assumes that you compile the source code into an assembly, place it in a Bin subfolder of your Web application, and reference the assembly with a Register directive in your Web page. For a walkthrough that demonstrates both methods of compiling, see Walkthrough: Developing and Using a Custom Web Server Control.

using System;
using System.Security.Permissions;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace Samples.AspNet.CS.Controls
  public class TextDisplayWebPart : WebPart
    private String _contentText = null;
    TextBox input;
    Label DisplayContent;
    const string _subTitle = "Contoso, Ltd";

    public TextDisplayWebPart()
      this.AllowClose = false;

    [Personalizable(), WebBrowsable]
    public String ContentText
      get { return _contentText; }
      set { _contentText = value; }

    protected override void CreateChildControls()
      DisplayContent = new Label();
      DisplayContent.BackColor = 
      DisplayContent.Text = this.ContentText;
      input = new TextBox();
      Button update = new Button();
      update.Text = "Set Label Content";
      update.Click += new EventHandler(this.submit_Click);
      ChildControlsCreated = true;

    public override string Subtitle
      get {return _subTitle; }

    private void submit_Click(object sender, EventArgs e)
      // Update the label string.
      if (input.Text != String.Empty)
        _contentText = input.Text + @"<br />";
        input.Text = String.Empty;
        DisplayContent.Text = this.ContentText;

The second part of the example is a Web page that shows how to reference the TextDisplayWebPart control in an ASP.NET Web page. After you load the page in a browser, the control's title bar text includes the title assigned to the control in the declarative markup, a hyphen separator, and the value of the custom subtitle from the TextDisplayWebPart control.

<%@ page language="C#" %>
<%@ register tagprefix="aspSample" 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
  <form id="Form1" runat="server">
      <asp:webpartmanager id="WebPartManager1" runat="server" />
      title="Zone 1"
        <parttitlestyle font-bold="true" ForeColor="#3300cc" />
          bordercolor="#81AAF2" />
            title = "Text WebPart" 

.NET Framework
Available since 2.0
Return to top