WebPart.Subtitle Property


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 Overridable ReadOnly Property Subtitle As String

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.

Imports System
Imports System.Security.Permissions 
Imports System.Web
Imports System.Web.UI.WebControls 
Imports System.Web.UI.WebControls.WebParts

Namespace Samples.AspNet.VB.Controls

<AspNetHostingPermission(SecurityAction.Demand, _ 
  Level := AspNetHostingPermissionLevel.Minimal)> _ 
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
  Level := AspNetHostingPermissionLevel.Minimal)> _ 
Public Class TextDisplayWebPart 
  Inherits WebPart
  Private _contentText As String = Nothing
  Private input As TextBox
  Private DisplayContent As Label 
  Private Const _subTitle as String = "Contoso, Ltd"

  Public Sub New()  
    Me.AllowClose = False 
  End Sub 

  <Personalizable(), WebBrowsable()>  _ 
  Public Property ContentText() As String 
      Return _contentText 
    End Get 
      _contentText = value
    End Set 
  End Property

  Protected Overrides Sub CreateChildControls() 
    DisplayContent = New Label()
    DisplayContent.Text = Me.ContentText
    DisplayContent.BackColor = _
    input = New TextBox() 
    Dim update As New Button()
    update.Text = "Set Label Content" 
    AddHandler update.Click, AddressOf Me.submit_Click
    ChildControlsCreated = True 

  End Sub 

  Public Overrides ReadOnly Property Subtitle() As String
      Return _subTitle 
    End Get
  End Property

  Private Sub submit_Click(ByVal sender As Object, _
                           ByVal e As EventArgs)  
    ' Update the label string.
    If input.Text <> String.Empty Then
      _contentText = input.Text & "<br />"
      input.Text = String.Empty 
      DisplayContent.Text = Me.ContentText
    End If

  End Sub 

End Class 

End Namespace 

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="VB" %>
<%@ 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