Condividi tramite


IWebPart.Subtitle Proprietà

Definizione

Ottiene una stringa concatenata con il valore della Title proprietà per formare un titolo completo per un WebPart controllo.

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

Valore della proprietà

Stringa che funge da sottotitolo per il controllo. Il valore predefinito è una stringa vuota ("").

Esempio

Nell'esempio di codice seguente viene illustrato l'uso dichiarativo e programmatico della Subtitle proprietà . Il codice sorgente completo per l'esempio è disponibile nella sezione Esempio della panoramica della IWebPart classe.

La prima parte dell'esempio di codice mostra come il controllo utente implementa la Subtitle proprietà . Si noti che la proprietà è di sola lettura e deve essere usata per fornire un sottotitolo predefinito aggiunto al titolo principale di un controllo.

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

La seconda parte dell'esempio di codice mostra come viene fatto riferimento al controllo utente che implementa l'interfaccia IWebPart in un WebPartZone controllo e come le proprietà scrivibili da IWebPart vengono impostate in modo dichiarativo sul controllo. Dopo aver caricato la pagina in un browser, si noti che il valore predefinito della Subtitle proprietà , impostato nel codice di implementazione del controllo utente, viene aggiunto al titolo nella barra del titolo del controllo.

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

Commenti

La Subtitle proprietà viene utilizzata per restituire una stringa di sottotitolo predefinita per un WebPart controllo aggiunto al titolo del controllo nella barra del titolo.

Se si specifica un valore predefinito per la Subtitle proprietà in un controllo che implementa l'interfaccia IWebPart , il controllo Web part impostato lo aggiunge automaticamente al valore della Title proprietà del controllo in fase di esecuzione.

Si applica a

Vedi anche