NavigateURL: How to make A DotNetNukeŽ link (in VB and C#)

A DotNetNuke module is a collection of User Controls (.ascx files)  that are grouped together by a module definition. If you look at the code for the Core project modules you will see that most modules only contain one View, Edit, and Settings control. There are plenty of examples for navigating between those controls. For example:

To navigate from the View control to the Edit control you can use code such as this:

Response.Redirect(EditUrl())

To navigate from the Edit control to the View control you can use code such as this:

Response.Redirect(Globals.NavigateURL(), true)

You usually don't need a link for the Settings control. You simply configure the User Control in in the module definition as a Settings control and a link is automatically created in the module's menu to navigate to it.

Navigating to a User Control in Your Module

If you want to navigate to User Control other than the default controls covered above, you have to perform a few steps.

1) Create the User Control (see my tutorial Super-Simple Module (DAL+) on how to create User Controls). In this example I have created a User Control called EditMyGallery.ascx.

2) Add the User Control to the Module definition and give it a unique key.

The unique key I have given this control is mygallery.

Notice the Module name is DefGallery. This is important and will be used in the next step.

The Type has been set to View. In my module I intend for the EditMyGallery.ascx control to be accessible by all users who have access to the View controls.

However, realize that the Portal administrator is able to configure the security access for the different types of controls. The Portal administrator usually configures the module to allow all users to access the View controls (even users who have not logged in).

 

However, this is not always the case. The Portal may be a private portal that requires a person to be logged in to use the module. In that case the Portal administrator will configure the View controls for the module to be accessible only by Registered Users.

You simply indicate a security group for the control. The Portal administrator will ultimately decide which users actually have access to the control.

VERY IMPORTANT

In the Module definition, you must set the Default Cache Time to 0 (and click the Update Cache Properties button to set it). Otherwise your links may not work properly because of module caching.

Using NavigateURL

Now that your module configuration is set you can use the NavigateURL method. When you look at the NavigateURL method in the object browser you can see that it has a number of overloads

The overload that we will use is:

Public Function NavigateURL
(
ByVal TabID As Integer,
ByVal ControlKey As String,
ByVal ParamArray AdditionalParameters() As String
)
As String

(note: you will want to add DotNetNuke.Common to the Imports statement (for VB.NET) or using statement (for C#) to use the code below)

You can use the following code to navigate to the User Control:

C#:

protected void cmdEdit_Click(object sender, EventArgs e)
{
  Response.Redirect(
Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "mygallery", "mid=" + ModuleId.ToString()
));
}

VB.NET:

Protected Sub cmdEdit_Click(ByVal sender As Object, ByVal e As EventArgs)
  Response.Redirect(Globals.NavigateURL(PortalSettings.ActiveTab.TabID,
"mygallery", "mid=" & Cstr(ModuleID)))
End Sub

This code creates a URL such as:

http://localhost/MyDNNWebsite/Home/tabid/36/ctl/mygallery/mid/362/Default.aspx

The code:

PortalSettings.ActiveTab.TabID

Inserts tabid/36 into the URL so that the DotNetNuke framework knows which page to go to (in this example we want to go to the current page).

The "mygallery" parameter inserts mygallery after ctl. This instructs the DotNetNuke framework to load the User Control that is configured with the mygallery key. The code:

"mid=" + ModuleId.ToString()

inserts mid/362 into the URL so that the DotNetNuke framework knows which module to load.

[Back to: The ADefWebserver DotNetNuke HELP WebSite]

DotNetNukeŽ is a registered trademark of Perpetual Motion Interactive Systems Inc.