語言

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

屬性值

一個作為控制副標題的字串。 預設值是空字串 ("")。

範例

以下程式碼範例展示了該 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實作WebPartZone介面的使用者控制項,以及可撰寫的屬性IWebPart如何在控制項上宣告式設定。 在瀏覽器載入頁面後,請注意該屬性的預設值 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 。

如果你在實Subtitle作介面的控制項中提供該屬性的預設值IWebPart,Web Parts 控制集會在執行時自動將其附加到控制項屬性的值Title上。

適用於

另請參閱