GenericWebPart.Title 属性
定义
获取或设置 GenericWebPart 控件的标题。Gets or sets the title of a GenericWebPart control.
public:
virtual property System::String ^ Title { System::String ^ get(); void set(System::String ^ value); };
public override string Title { get; set; }
member this.Title : string with get, set
Public Overrides Property Title As String
属性值
一个表示部件控件的标题的字符串。A string that represents the title of the part control. 默认值为空字符串 ("")。The default value is an empty string ("").
示例
下面的代码示例演示如何声明和编程方式使用 Title 属性。The following code example demonstrates declarative and programmatic use of the Title property. 该示例的完整源代码位于概述主题的 "示例" 部分 GenericWebPart 。The complete source code for the example is found in the Example section of the GenericWebPart overview topic.
此代码示例的第一部分演示了如何 Title 在控件内的服务器控件上以声明方式设置属性 WebPartZone 。The first part of the code example shows how the Title property is set declaratively on a server control within a WebPartZone control.
<asp:WebPartZone ID="WebPartZone1" runat="server">
<ZoneTemplate>
<asp:Calendar ID="Calendar1" runat="server"
Title="My Calendar"
Description="A calendar used as a GenericWebPart control."
CatalogIconImageUrl="MyCatalogIcon.gif"
TitleIconimageUrl ="MyTitleIcon.gif"
TitleUrl="MyInfoUrl.htm"
Width="250"/>
</ZoneTemplate>
</asp:WebPartZone>
<asp:WebPartZone ID="WebPartZone1" runat="server">
<ZoneTemplate>
<asp:Calendar ID="Calendar1" runat="server"
Title="My Calendar"
Description="A calendar used as a GenericWebPart control."
CatalogIconImageUrl="MyCatalogIcon.gif"
TitleIconimageUrl ="MyTitleIcon.gif"
TitleUrl="MyInfoUrl.htm"
Width="250"/>
</ZoneTemplate>
</asp:WebPartZone>
此代码示例的第二部分演示如何以编程方式访问属性,以便在标签中显示其值。The second part of the code example demonstrates how to access the property programmatically to display its value in a label.
protected void Button1_Click(object sender, EventArgs e)
{
Label2.Text =
@"<h3>Calendar GenericWebPart Properties</h3>" +
"<em>Title: </em>" + calendarPart.Title +
"<br />" +
"<em>CatalogIconImageUrl: </em>" + calendarPart.CatalogIconImageUrl +
"<br />" +
"<em>TitleUrl: </em>" + calendarPart.TitleUrl +
"<br />" +
"<em>Decription: </em>" + calendarPart.Description +
"<br />" +
"<em>TitleIconImageUrl: </em>" + calendarPart.TitleIconImageUrl +
"<br />" +
"<em>ChildControl ID: </em>" + calendarPart.ChildControl.ID +
"<br />" +
"<em>ChildControl Type: </em>" + calendarPart.ChildControl.GetType().Name +
"<br />" +
"<em>GenericWebPart ID: </em>" + calendarPart.ID +
"<br />" +
"<em>GenericWebPart Type: </em>" + calendarPart.GetType().Name +
"<br />" +
"<em>GenericWebPart Parent ID: </em>" + calendarPart.Parent.ID;
Label3.Text =
@"<h3>BulletedList GenericWebPart Properties</h3>" +
"<em>Title: </em>" + listPart.Title +
"<br />" +
"<em>CatalogIconImageUrl: </em>" + listPart.CatalogIconImageUrl +
"<br />" +
"<em>TitleUrl: </em>" + listPart.TitleUrl +
"<br />" +
"<em>Decription: </em>" + listPart.Description +
"<br />" +
"<em>TitleIconImageUrl: </em>" + listPart.TitleIconImageUrl +
"<br />" +
"<em>ChildControl ID: </em>" + listPart.ChildControl.ID +
"<br />" +
"<em>ChildControl Type: </em>" + listPart.ChildControl.GetType().Name +
"<br />" +
"<em>GenericWebPart ID: </em>" + listPart.ID +
"<br />" +
"<em>GenericWebPart Type: </em>" + listPart.GetType().Name +
"<br />" +
"<em>GenericWebPart Parent ID: </em>" + listPart.Parent.ID;
}
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Label2.Text = _
"<h3>Calendar GenericWebPart Properties</h3>" & _
"<em>Title: </em>" & calendarPart.Title & _
"<br />" & _
"<em>CatalogIconImageUrl: </em>" & calendarPart.CatalogIconImageUrl & _
"<br />" & _
"<em>TitleUrl: </em>" & calendarPart.TitleUrl & _
"<br />" & _
"<em>Decription: </em>" & calendarPart.Description & _
"<br />" & _
"<em>TitleIconImageUrl: </em>" & calendarPart.TitleIconImageUrl & _
"<br />" & _
"<em>ChildControl ID: </em>" & calendarPart.ChildControl.ID & _
"<br />" & _
"<em>ChildControl Type: </em>" & calendarPart.ChildControl.GetType().Name & _
"<br />" & _
"<em>GenericWebPart ID: </em>" & calendarPart.ID & _
"<br />" & _
"<em>GenericWebPart Type: </em>" & calendarPart.GetType().Name & _
"<br />" & _
"<em>GenericWebPart Parent ID: </em>" & calendarPart.Parent.ID
Label3.Text = _
"<h3>BulletedList GenericWebPart Properties</h3>" & _
"<em>Title: </em>" & listPart.Title & _
"<br />" & _
"<em>CatalogIconImageUrl: </em>" & listPart.CatalogIconImageUrl & _
"<br />" & _
"<em>TitleUrl: </em>" & listPart.TitleUrl & _
"<br />" & _
"<em>Decription: </em>" & listPart.Description & _
"<br />" & _
"<em>TitleIconImageUrl: </em>" & listPart.TitleIconImageUrl & _
"<br />" & _
"<em>ChildControl ID: </em>" & listPart.ChildControl.ID & _
"<br />" & _
"<em>ChildControl Type: </em>" & listPart.ChildControl.GetType().Name & _
"<br />" & _
"<em>GenericWebPart ID: </em>" & listPart.ID & _
"<br />" & _
"<em>GenericWebPart Type: </em>" & listPart.GetType().Name & _
"<br />" & _
"<em>GenericWebPart Parent ID: </em>" & listPart.Parent.ID
End Sub
End Class
注解
部件控件的标题栏中的可见标题文本由 Title 属性设置。The visible title text in a part control's title bar is set by the Title property.
如果没有为控件提供标题,则 Web 部件控件集会自动计算要用作标题的默认字符串。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. 有关详细信息,请参阅 DisplayTitle。For more information, see DisplayTitle. 此外,还可以提供追加到标题字符串的默认副标题。Also, it is possible to provide a default subtitle that is appended to the title string. 有关详细信息,请参阅 Subtitle。For details, see Subtitle.
此属性将重写基属性,以便可以访问子控件上的属性,就像它是真正的 WebPart 控件一样。This property overrides the base property so that you can access the property on the child control as if it were a true WebPart control.
您可以在网页的声明性标记中,也可以通过编程方式设置控件的属性的值。You can set values for the property on your control in the declarative markup of a Web page, as well as programmatically. 若要在每次使用控件时为属性提供默认值,可以实现 IWebPart 接口。To provide a default value for the property whenever the control is used, you can implement the IWebPart interface.