IWebPart.Title Propriedade
Definição
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
Valor da propriedade
Uma cadeia de caracteres que contém o título do controle.A string that contains the title of the control. O valor padrão é uma cadeia de caracteres vazia ("").The default value is an empty string ("").
Exemplos
O exemplo de código a seguir demonstra o uso declarativa e programático da Title propriedade.The following code example demonstrates declarative and programmatic use of the Title property. O código-fonte completo do exemplo é encontrado na seção de exemplo da IWebPart classe visão geral.The complete source code for the example is found in the Example section of the IWebPart class overview.
A primeira parte do exemplo de código mostra como o controle de usuário implementa a Title propriedade.The first part of the code example shows how the user control implements the Title property.
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
A segunda parte do exemplo de código demonstra o método no controle de usuário que define programaticamente o valor da Title propriedade quando um usuário seleciona o nome de propriedade apropriado nos botões de opção na página, define um novo valor na caixa de texto e clica no botão Atualizar .The second part of the code example demonstrates the method in the user control that programmatically sets the value of the Title property when a user selects the appropriate property name from the radio buttons on the page, sets a new value in the text box, and then clicks the Update button.
Importante
Este exemplo tem uma caixa de texto que aceita a entrada do usuário, que é uma possível ameaça à segurança.This example has a text box that accepts user input, which is a potential security threat. Por padrão, as páginas da Web do ASP.NET validam que a entrada do usuário não inclui elementos de script ou HTML.By default, ASP.NET Web pages validate that user input does not include script or HTML elements. Para obter mais informações, consulte Visão geral de explorações de script.For more information, see Script Exploits Overview.
// 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
A terceira parte do exemplo de código mostra como o controle de usuário que implementa a IWebPart interface é referenciado em um WebPartZone controle e como a Title propriedade é definida declarativamente no controle.The third part of the code example shows how the user control that implements the IWebPart interface is referenced in a WebPartZone control, and how the Title property is set declaratively on the control.
<%@ 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>
Comentários
O texto do título visível na barra de título de um controle é definido pela Title propriedade.The visible title text in a control's title bar is set by the Title property.
Se você não fornecer um título para um controle, o conjunto de controle Web Parts calculará automaticamente uma cadeia de caracteres padrão para usar como um título.If you do not supply a title for a control, the Web Parts control set automatically calculates a default string to use as a title. Para obter mais informações, consulte DisplayTitle.For more information, see DisplayTitle. Além disso, é possível fornecer um subtítulo padrão que é anexado à cadeia de caracteres de título.Also, it is possible to provide a default subtitle that is appended to the title string. Para obter detalhes, consulte Subtitle.For details, see Subtitle.