Επεξεργασία

Κοινή χρήση μέσω


IWebPart.Subtitle Property

Definition

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

public:
 property System::String ^ Subtitle { System::String ^ get(); };
public string Subtitle { get; }
member this.Subtitle : string
Public ReadOnly Property Subtitle As String

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.

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

    return (string)objSubTitle;
  }

}
ReadOnly Property Subtitle() As String _
  Implements IWebPart.Subtitle
  Get
    Dim objSubTitle As Object = ViewState("Subtitle")
    If objSubTitle Is Nothing Then
      Return "My Subtitle"
    End If
    Return CStr(objSubTitle)
  End Get
End Property

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.

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

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

See also