Welcome to Bilal Haidar [MVP, MCT] Official Blog Sign in | Join | Help

AddMessageModule in DotNetNuke

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,

Published Saturday, March 04, 2006 11:38 AM by BilalHaidar [MVP]
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: AddMessageModule in DotNetNuke

Thanks-a-ton for the code snippet; works great; just what I was looking for...
Monday, March 20, 2006 9:33 PM by DNN Developer

# re: AddMessageModule in DotNetNuke

Could you blog a brief on customizing and extending registration, and how you implemented this method? I'm running into lots of challenges with extending registration, and am debating on just buying a registration module from a third party.
Thursday, March 30, 2006 2:17 AM by rmo

Leave a Comment

(required) 
required 
(required)