IWebPart.TitleUrl 属性
定义
public:
property System::String ^ TitleUrl { System::String ^ get(); void set(System::String ^ value); };
public string TitleUrl { get; set; }
member this.TitleUrl : string with get, set
Public Property TitleUrl As String
属性值
一个字符串,表示有关 WebPart 控件更多信息的 URL。A string that represents a URL to more information about a WebPart control. 默认值为空字符串 ("")。The default value is an empty string ("").
示例
下面的代码示例演示如何声明和编程方式使用 TitleUrl 属性。The following code example demonstrates declarative and programmatic use of the TitleUrl property. 该示例的完整源代码位于类概述的 "示例" 部分 IWebPart 。The complete source code for the example is found in the Example section of the IWebPart class overview.
此代码示例的第一部分演示用户控件如何实现 TitleUrl 属性。The first part of the code example shows how the user control implements the TitleUrl property.
public string TitleUrl
{
get
{
object objTitle = ViewState["TitleUrl"];
if (objTitle == null)
return String.Empty;
return (string)objTitle;
}
set
{
ViewState["TitleUrl"] = value;
}
}
Public Property TitleUrl() As String _
Implements IWebPart.TitleUrl
Get
Dim objTitle As Object = ViewState("TitleUrl")
If objTitle Is Nothing Then
Return String.Empty
End If
Return CStr(objTitle)
End Get
Set(ByVal value As String)
ViewState("TitleUrl") = value
End Set
End Property
此代码示例的第二部分演示用户控件中的方法, TitleUrl 当用户从页面上的单选按钮中选择相应的属性名称、在文本框中设置新值,然后单击 " 更新 " 按钮时,该方法以编程方式设置属性的值。The second part of the code example demonstrates the method in the user control that programmatically sets the value of the TitleUrl 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.
重要
此示例具有一个接受用户输入的文本框,这是一个潜在的安全威胁。This example has a text box that accepts user input, which is a potential security threat. 默认情况下,ASP.NET 网页验证用户输入是否不包含脚本或 HTML 元素。By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 有关详细信息,请参阅脚本侵入概述。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
此代码示例的第三部分演示如何 IWebPart 在控件中引用实现接口的用户控件 WebPartZone ,以及如何 TitleUrl 在控件上以声明方式设置该属性。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 TitleUrl property is set declaratively on the control. 请注意,如果未提供实际页面的 URL,然后用户单击标题栏中的链接,则会出现一条错误消息。Note that if you do not provide a URL to a real page, and then a user clicks the link in the title bar, an error message appears.
<%@ 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>
注解
为属性分配 URL 时 TitleUrl ,控件的标题将变为链接。When you assign a URL to the TitleUrl property, the title of the control becomes a link. 此属性的目的是为最终用户提供一种方便的方法来访问有关控件的其他信息。The purpose of this property is to provide a convenient way for end users to access additional information about a control. 其他信息可能提供版权数据、联系数据、有关控件创建者的详细信息,或控件用途的摘要。The additional information could provide copyright data, contact data, details about the creator of the control, or a summary of the control's purpose.
备注
通常,不使用 TitleUrl 属性链接到帮助内容。Normally, you would not use the TitleUrl property to link to Help content. 为控件提供帮助链接的最佳方式是使用 HelpUrl 属性。The best way to provide a link to Help for a control is to use the HelpUrl property.