Click here to Skip to main content
13,143,618 members (31,551 online)
Click here to Skip to main content
Add your own
alternative version


15 bookmarked
Posted 24 Feb 2008


, 24 Feb 2008
Rate this:
Please Sign up or sign in to vote.

How to redirect to specific control of a specific tab in DotNetNuke

Hi friends. DotNetNuke is a well known open source CMS. When I go through the forums of the website, there exists a common question many times by different developers that how to redirect to a specific control at the specific tab in DotNetNuke. I will try to help the new developers getting answer of this question.


As every newbie starting the DotNetNuke development has always a question like this in their lives. The basic idea behind doing this is: <o:p />

  • We need TABID for redirection to specific TAB. we will pass a query string parameter along with the redirect URL to tell which control to load.<o:p />
  • At the default control of that specific module, we will just read the query string and load .ASCX control accordingly into a placeholder control. <o:p />

I’m trying to make sure how easily we can do this using an example.<o:p />


Create a default control<o:p />

Create a control called _default in your root directory which looks like this:


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="_Default.ascx.cs" Inherits="PMJ.Modules.Contact._Default" %>
<table id="Table1" cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
        <td valign="top" align="center">
            <p align="center">
                <asp:PlaceHolder ID="phMain" runat="server"></asp:PlaceHolder>
        <td valign="top" align="center">
            <asp:Label ID="lblModuleSettings" runat="server" resourcekey="lblModuleSettings"

                ForeColor="Red" Visible="False">Please update module Portal Admin.</asp:Label></td>


partial class _Default : PortalModuleBase
        private string m_ModuelControl = "Contacts.ascx";//1. Default Module Control to load
        protected void Page_Load(object sender, EventArgs e)
            LoadModuleControl(); // Call LoadModuleControl Method to load a specific control
        private void LoadModuleControl()
            if (Request.QueryString["mctl"] != null)//3. Read control name from querystring
                 m_ModuelControl = Request.QueryString["mctl"].ToString() + ".ascx";
             //4. check authorization here if you want, otherwise comment out or skip this step
            switch (m_ModuelControl)
                case "AddContact.ascx":
                    //5. check if user is authorized otherwise redirect to access denied page
                    //    Response.Redirect(Globals.NavigateURL("Access Denied"), true);
                case "ContactNotes.ascx":
            //6. Load a specific control
            PortalModuleBase objPortalModuleBase = (PortalModuleBase)LoadControl(m_ModuelControl);
            objPortalModuleBase.ModuleConfiguration = ModuleConfiguration;
            objPortalModuleBase.ID = System.IO.Path.GetFileNameWithoutExtension(m_ModuelControl);

Quick expaination of the code

So let’s step by step go through the details of the code.

  1. If you look at the bold code in _default.ascx, <asp:PlaceHolder ID="phMain" runat="server"></asp:PlaceHolder>, that is a place holder control of in which we will load another .ascx control at runtime.
  2. Now if you look at the code in _default.aspx.cs you can find the steps in the comment at various places of the code.
  3. Use a private variable to hold the control name into it. Initialize it with the default control that we will load if no query string parameter is found in the URL.
  4. Initialize the variable with the query string parameter if it is specified in the URL
  5. Include the switch statement for authorization if you need to authorize the user, Otherwise put that code in comment
  6. Load the specific control in the phMain placeholder of the default control.

So the last thing to do is, When you redirect from any tab, just do this:

TabController objtab = new TabController();
TabInfo objtabinfo = new TabInfo();
objtabinfo = objtab.GetTabByName("Contacts", PortalId);
Response.Redirect(Globals.NavigateURL(objtabinfo.TabID, "", "mctl=" + "ContactNote")));

Remember that for this code to work: • You need a tab called “Contacts“ in your portal • You need a control called ContactNote.ascx in your module • You need to include the namespace DotNetNuke.Entities.Tabs at the top of your page where you write the redirect code above. Wish you a Happy coding with DotNetNuke.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Prashant Lakhlani
Web Developer
India India
I'm Computer Engineer with 4+ years experience having good exposure of microsoft related technologies. I worked on, sql server, html/dhtml css, javascript, jQuery, mvc, java, wso2, java web services, basics of html and many more things

I'm running some open source projects like and contributor in couple of open source projects like

I love to hear from you guys about anything that I can help

You may also be interested in...


Comments and Discussions

Generalhi Prashant Lakhlani Pin
ajay_m23-Jan-09 22:43
memberajay_m23-Jan-09 22:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170915.1 | Last Updated 25 Feb 2008
Article Copyright 2008 by Prashant Lakhlani
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid