IWebPart.Subtitle 属性

定义

获取一个字符串,该字符串与 Title 属性值连接即形成 WebPart 控件的完整标题。

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

属性值

String

作为控件副标题的字符串。 默认值为空字符串 ("")。

示例

下面的代码示例演示了属性的 Subtitle 声明性和编程用法。 示例的完整源代码位于类概述的 IWebPart “示例”部分中。

代码示例的第一部分显示用户控件如何实现 Subtitle 属性。 请注意,该属性是只读的,用于提供追加到控件主标题的默认副标题。

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

代码示例的第二部分演示如何在控件中引用实现IWebPart接口的用户控件,以及如何在控件上以声明方式设置可写属性IWebPartWebPartZone 在浏览器中加载页面后,请注意,在用户控件的实现代码中设置的属性的默认值 Subtitle 将追加到控件标题栏中的标题。

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

注解

Subtitle 属性用于返回附加到标题栏中控件标题的控件的默认副标题字符串 WebPart

如果在实现IWebPart接口的控件中为Subtitle属性提供默认值,则Web 部件控件集会自动将其追加到运行时控件的属性的值Title

适用于

另请参阅