Mar 4 2006

AddMessageModule in DotNetNuke

Category: DotNetNuke — Bil@l @ 21:38

I was developing a Custom Registration Module in DotNetNuke. I followed the same technique used in the default registration module that comes with DotNetNuke, however, I had to do my own cutomizations and using my own tables and objects.

I noticed the heavy use of AddModuleMessage used by this module. This method does nothing but show a message at the top of the module.

I digged a bit in the DotNetNuke code and knew that when the page loads, the DNN creates the default page, and adds a PlaceHolder called MessagePlaceHolder(if not mistaken), to the top of the ContentPane Section of the page above any module added. So when an error happens, DNN finds this PlaceHolder, make it visible and display the error inside it.

My problem was that, the registration form found at www.devconnect.net was a long form, and sometimes the page is showing the last items in the form, and the user pressed the Register button, if there is an error above, the user will stay in his/her same position without noticing what happened. All what happened was that a problem like a field was not filled is required or a system error happened, like username using is used in th database with another user. The latter message is displayed by DNN in the PlaceHolder and the method placing the error there is the AddModuleMessage. What I wanted is that, when an error happens, I need the user to be able to see the error, how? I created the method below to make the page automatically scroll to the PlaceHolder that is showing the error message after a call to the AddModuleMessage method is done, check the code and the comments below:

// Scroll to top of module
public void Scroll2TopModule()
{
    // Set page position on top when the AddModuleMessage is functional
    // First I found the place holder containing the error message displayed by AddModuleMessage
        PlaceHolder msgHolder = (PlaceHolder)this.Parent.FindControl("MessagePlaceHolder");

    // If this place holder is visible, it is only visible when the AddModuleMesssage is called
    if (msgHolder.Visible)
        {
            // I down casted the current PortalModuleBase’s page into the CDefault, which I 
            // think it is the default page of the portal
            // then, I used the ScrollToControl method found in the default.aspx page, 
            // this method takes as input a control to scroll to
            // I gave it the parent of the Message Holder, why? The Message holder is usually added 
            // to the Content Page, so I told the method to scroll to the head of the Content Pane
                ((CDefault)this.Page).ScrollToControl(msgHolder.Parent);
        }
}

I hope this method helps you. It helped me a lot.

Regards,

Tags:

Comments are closed