Skip to main content

XRControl.NavigateUrl Property

Bindable. Specifies the URL to navigate to when a control is clicked.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v24.2.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

[DefaultValue("")]
[SRCategory(ReportStringId.CatNavigation)]
public virtual string NavigateUrl { get; set; }

Property Value

Type Default Description
String String.Empty

A string that corresponds to a URL.

Remarks

Use the NavigateUrl property to specify the URL of a web page to which a web browser navigates when you click a control. Start the URL of a web page with a “http://“ or “https://“ prefix. To specify a window or frame in which a browser opens a new page, use the control’s Target property.

You can also specify an absolute or relative path to a file in the NavigateUrl property.

If you set the Target property to _self, you can create a link in the same document. For this, set the NavigateUrl property to the target control’s Name property value.

For more information, review the following help topic: Add Cross-References and Hyperlinks.

Note

Not all XRControl class descendants implement the NavigateUrl property. For example, this property is hidden in the Band class descendants.

Specify Execution Policy for User-Invoked Processes

When you click a control with a specified NavigateUrl property, a new process is started. For example, if the property points to a web page, a browser is opened. In case of a .txt file, the default text editor is executed.

You can specify an execution policy for processes users initiate to avoid possible security issues. To do that, call one of the DevExpress.Data.Utils.ProcessStartPolicy class methods at application startup:

  • SuppressAll() - suppresses all processes. You can click controls with a specified NavigateUrl property but no processes are executed.
  • ThrowAlways() - throws an exception when a process starts.
  • RequireConfirmation() - shows a confirmation dialog that prompts you to confirm or cancel a process.

If you do not call these methods, processes are not affected when you click a control.

The following code suppresses all processes users initiate:

static void Main() {  
    DevExpress.Data.Utils.ProcessStartPolicy.SuppressAll();  
    //...  
} 

Execute JavaScript Code

You can add a “javascript:” prefix to the NavigateUrl property in the Web End-User Report Designer and execute JavaScript code on the client. Since this makes other users vulnerable to cross-site scripting (XSS) attacks, JavaScript code execution is disabled in the ASPxWebDocumentViewer control. If your application uses JavaScript code in URLs, use the following properties to enable JavaScript code execution:

Bind to Data

You can bind the NavigateUrl property to a data field in a report’s data source. For more information, refer to the following article: Bind Report Controls to Data.

Example

This example demonstrates how to use the XRLabel control to create a hyperlink.

The code below creates the XRLabel control, sets up its appearance, and specifies its NavigateUrl and Target properties.

using System.Drawing;
using DevExpress.XtraReports.UI;
// ...

public XRLabel CreateHyperlink(){
    // Create a label for a hyperlink.
    XRLabel hyperlinkLabel = new XRLabel();

    // Set its main properties.
    hyperlinkLabel.Text = "DevExpress Inc.";
    hyperlinkLabel.Width = 200;
    hyperlinkLabel.ForeColor = Color.Blue;
    hyperlinkLabel.Font = new Font("Tahoma", 12, FontStyle.Underline);

    // Set its URL and target.
    hyperlinkLabel.NavigateUrl = "https://www.devexpress.com/";
    hyperlinkLabel.Target = "_blank";

    return hyperlinkLabel;
}

To add the hyperlink to the report’s Detail band, handle the report’s BeforePrint event:

using DevExpress.XtraReports.UI;
// ...

private void XtraReport1_BeforePrint(object sender, System.ComponentModel.EventArgs e) {
    // Create a new hyperlink and add it to the report's Detail Band.
    Bands.GetBandByType(typeof(DetailBand)).Controls.Add(CreateHyperlink());
}

The label behaves like a hyperlink in a report’s Print Preview and in a document exported to HTML, PDF, RTF, XLS, and XLSX formats.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the NavigateUrl property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also