IWebPart.TitleUrl 屬性

定義

取得或設定至 WebPart 控制項之補充資訊的 URL。

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

屬性值

String

字串,表示至 WebPart 控制項之詳細資訊的 URL。 預設值為空字串 ("")。

範例

下列程式碼範例示範屬性的 TitleUrl 宣告式和程式設計用法。 範例的完整原始程式碼位於類別概觀的 IWebPart Example 區段中。

程式碼範例的第一個部分示範使用者控制項如何實作 TitleUrl 屬性。

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

重要

這個範例有一個可接受使用者輸入的文字方塊,這可能會造成安全性威脅。 根據預設,ASP.NET Web 網頁會驗證使用者輸入未包含指令碼或 HTML 項目。 如需詳細資訊,請參閱 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

程式碼範例的第三個部分示範如何在 控制項中 WebPartZone 參考實 IWebPart 作介面的使用者控制項,以及如何以 TitleUrl 宣告方式在控制項上設定 屬性。 請注意,如果您未提供真實頁面的 URL,然後使用者按一下標題列中的連結,就會顯示錯誤訊息。

<%@ 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 屬性時,控制項的標題會變成連結。 此屬性的目的是要提供方便的方式,讓使用者存取控制項的其他資訊。 其他資訊可以提供著作權資料、連絡資料、控制項建立者的詳細資料,或控制項用途的摘要。

注意

一般而言,您不會使用 TitleUrl 屬性連結至 [說明] 內容。 提供控制項說明連結的最佳方式是使用 HelpUrl 屬性。

適用於

另請參閱