IWebPart.Title Proprietà

Definizione

Ottiene o imposta il titolo di un controllo WebPart.

public:
 property System::String ^ Title { System::String ^ get(); void set(System::String ^ value); };
public string Title { get; set; }
member this.Title : string with get, set
Public Property Title As String

Valore della proprietà

Stringa che contiene il titolo del controllo. Il valore predefinito è una stringa vuota ("").

Esempio

Nell'esempio di codice seguente viene illustrato l'uso dichiarativo e programmatico della Title 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 Title proprietà .

public string Title
{
  get
  {
    object objTitle = ViewState["Title"];
    if (objTitle == null)
      return String.Empty;

    return (string)objTitle;
  }
  set
  {
    ViewState["Title"] = value;
  }
}
Public Property Title() As String _
  Implements IWebPart.Title
  Get
    Dim objTitle As Object = ViewState("Title")
    If objTitle Is Nothing Then
      Return String.Empty
    End If
    Return CStr(objTitle)
  End Get
  Set(ByVal value As String)
    ViewState("Title") = value
  End Set
End Property

La seconda parte dell'esempio di codice illustra il metodo nel controllo utente che imposta a livello di codice il valore della Title proprietà quando un utente seleziona il nome di proprietà appropriato dai pulsanti di opzione nella pagina, imposta un nuovo valore nella casella di testo e quindi fa clic sul pulsante Aggiorna .

Importante

L'esempio include una casella di testo che accetta l'input dell'utente e rappresenta quindi una potenziale minaccia alla sicurezza. Per impostazione predefinita, le pagine Web ASP.NET verificano che l'input dell'utente non includa script o elementi HTML. Per altre informazioni, vedere Cenni preliminari sugli attacchi tramite script.

// Update the selected IWebPart property value.
void Button1_Click(object sender, EventArgs e)
{
  String propertyValue = Server.HtmlEncode(TextBox3.Text);
  TextBox3.Text = String.Empty;

  switch (RadioButtonList1.SelectedValue)
  {
    case "title":
      this.Title = propertyValue;
      break;
    case "description":
      this.Description = propertyValue;
      break;
    case "catalogiconimageurl":
      this.CatalogIconImageUrl = propertyValue;
      break;
    case "titleiconimageurl":
      this.TitleIconImageUrl = propertyValue;
      break;
    case "titleurl":
      this.TitleUrl = propertyValue;
      break;
    default:
      break;
  }
}
' Update the selected IWebPart property value.
Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
  Dim propertyValue As String = Server.HtmlEncode(TextBox3.Text)
  TextBox3.Text = String.Empty
    
  Select Case RadioButtonList1.SelectedValue
    Case "title"
      Me.Title = propertyValue
    Case "description"
      Me.Description = propertyValue
    Case "catalogiconimageurl"
      Me.CatalogIconImageUrl = propertyValue
    Case "titleiconimageurl"
      Me.TitleIconImageUrl = propertyValue
    Case "titleurl"
      Me.TitleUrl = propertyValue
    Case Else
  End Select

End Sub 'Button1_Click

Nella terza parte dell'esempio di codice viene illustrato come viene fatto riferimento al controllo utente che implementa l'interfaccia IWebPart in un WebPartZone controllo e come la Title proprietà viene impostata in modo dichiarativo sul 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

Il testo del titolo visibile nella barra del titolo di un controllo viene impostato dalla Title proprietà .

Se non si specifica un titolo per un controllo, il controllo Web part impostato calcola automaticamente una stringa predefinita da utilizzare come titolo. Per altre informazioni, vedere DisplayTitle. Inoltre, è possibile fornire un sottotitolo predefinito aggiunto alla stringa del titolo. Per informazioni dettagliate, vedere Subtitle.

Si applica a

Vedi anche