Custom technique, Action Menu, Navigation, Module path reference - Part 2

Ok. Let's continue. :)

Next, what i'm gonna show you is how to add custom drop down action menu.

Just open your Injector.ascx.cs, and watch this line :

public partial class DesktopModules_MyModule_MyModule : PortalModuleBase

Change it to :

public partial class DesktopModules_MyModule_MyModule : PortalModuleBase, IActionable

Hey ! What's the different ? Remember that every .ascx must inherit from DotNetNuke.Entities.Modules.PortalModuleBase. To add custom drop down list menu, you have to implement IActionable interface. That's why you have to implement it in your class. Create this code after you change your class declaration :

    public ModuleActionCollection ModuleActions
    {
        get
        {
            ModuleActionCollection myAction = new ModuleActionCollection();

            myAction.Add(GetNextActionID(),
                    "Goto Page2",
                    ModuleActionType.AddContent,
                    "",
                    "",
                    Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "", "ControlType=page2"),
                    false,
                    DotNetNuke.Security.SecurityAccessLevel.Edit,
                    true,
                    false);

            myAction.Add(GetNextActionID(),
                    "Goto Page3",
                    ModuleActionType.AddContent,
                    "",
                    "",
                    Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "", "ControlType=page3"),
                    false,
                    DotNetNuke.Security.SecurityAccessLevel.Edit,
                    true,
                    false);
            return myAction;
        }
    } 

This property is an implementation from IActionable interface. Create a ModuleActionCollection instance, name it with myAction. I will not cover in detail about parameters that are used in ModuleActionCollection. But only the important thing that you should understand. First parameter is a GetNextActionID() method. It is a method to create unique ID of your menu. Second parameter is a string that you want to put in your drop down action menu. You can use a resource file to separate string you want to use. In this case, i hardcode with "Goto Page2" and "Goto Page3". Sixth parameter is an action where your menu will be redirect to. In this case, every time a user click a "Goto Page2" menu link, i'm gonna redirect it to Injector.ascx again and passes a querystring with name "ControlType". This querystring then will be evaluated in ReadQueryString method. :) That's why i create a ReadQueryString method. So, based on ControlType querystring value, i pass a control into Injector.ascx. This technique is very flexible. Since i only register one control to DNN Framework. Another .ascx can be evaluated from ReadQueryString method.

Watch this code : 

Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "", "ControlType=page2")

This is a special method to redirect to another .ascx in DNN Framework. Usually you use code like this to redirect to another page :

Response.Redirect("Homepage.aspx");

But, in DNN Framework if you want to redirect to another ascx, you have to code like this :

Response.Redirect(Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "", "ControlType=page2"));

You have to pass a TabID (a menu), pass a control key (if it exists), and pass a whatever querystring parameter you want to use. If you're in the same page (the same Tab or the same menu), so you do not have to inclue PortalSettings.ActiveTab.TabID parameter. Just pass your control key or your querystring parameters.

So, everytime you want to redirect to another page, just type :

Response.Redirect(Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "", "ControlType=your_querystring_value_here"));

And everytime you want to add another control, just add some code from ReadQueryString() method based on your needs. 

And the last thing is, if you want to refer to you module path you can use this code :

this.ResolveUrl("your_image_or_css_or_js_file_here_with_extension");

ResolveUrl method is an override method that always return your relative path to your module project. It will always returns the correct path to your module project directory. You can explore more, for example, you can refer to HomeDirectory folder, or SkinPath folder, or Images folder, etc. All special folder can be accessed from DNN API.

You see that, DNN Framework provide a consistent and standar way how to develop module. It will makes your development become easier, consistent, standard, powerfull, robust, and secure (we will cover about security in my next articles).

See you next time in my DNN development module tutorial !

Share this post: | | | |
Published Tuesday, February 13, 2007 3:22 PM by agung
Filed under:

Comments

No Comments