Edit

Share via


IWebPart.TitleUrl Property

Definition

Gets or sets a URL to supplemental information about a WebPart control.

C#
public string TitleUrl { get; set; }

Property Value

A string that represents a URL to more information about a WebPart control. The default value is an empty string ("").

Examples

The following code example demonstrates declarative and programmatic use of the TitleUrl property. The complete source code for the example is found in the Example section of the IWebPart class overview.

The first part of the code example shows how the user control implements the TitleUrl property.

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

    return (string)objTitle;
  }
  set
  {
    ViewState["TitleUrl"] = value;
  }
}

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.

Important

This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

C#
// 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;
  }
}

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. 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.

ASP.NET (C#)
<%@ 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>

Remarks

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.

Note

Normally, you would not use the TitleUrl property to link to Help content. The best way to provide a link to Help for a control is to use the HelpUrl property.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also