Search code examples
asp.netuser-controlsdotnetnukedotnetnuke-moduledotnetnuke-7

How to redirect to another View(UserControl '.ascx') in DotnetNuke?


I am new in DotnetNuke. I don't know all the terminology of DotnetNuke. Please correct me. That will help me to improve.

I have create a Simple Project with 2 UserControl. 1- View.ascx, 2- ModuleInfo.ascx

1- View.ascx: It contains a button. I want to redirect it to another User Control ModuleInfo.ascx Here is code.

protected void btn1_Click(object sender, EventArgs e)
{
    Response.Redirect(DotNetNuke.Common.Globals.NavigateURL("ModuleInfo"), true);
}

2- ModuleInfo.ascx It contains static table.

How I added Module to DotnetNuke:

1- Add .zip file of build project to Admin --> Extension
2- Edit Module from Host --> Extension --> Edit Module --> Edit Definition --> Add Module Control --> Added key "ModuleInfo" and selected view.
3- Created new page and added module to it. 

When page load, View.aspx is fine. There is a button. But when I click on button, it will redirect to some page but it is blank. It should show the Table.

Can anybody please suggest me if I am missing anything here?


Solution

  • NavigateUrl must include tabId and moduleId in the additional arguments in order to work. A simpler method for navigating to views inside your module is simply use the base.EditUrl() which only needs the view's controlKey. See the below code snippet, both lines that set miUrl are equivalent.

    protected void btn1_Click(object sender, EventArgs e)
    {
        string miUrl = base.EditUrl("ModuleInfo");
        string miUrl = DotNetNuke.Common.Globals.NavigateURL(base.TabId, "ModuleInfo", String.Format("mid={0}", base.ModuleId));
    
        Response.Redirect(miUrl, true);
    }