AnodisedBlue Web Design Blog

Building a Simple Contact Form in DotNetNuke 5

Oct 6

Written by:
10/6/2011 3:26 PM  RssIcon

Building a Simple DotNetNuke© Contact Form


Project requirements:

Visual Studio Express 2005/2008 or Visual Studio 2005/2008 Professional.

Working DotNetNuke© 5+ Installation.

DotNetNuke Admin Rights.
C# or Visual Basic Knowledge.
ASP.Net 2.0 or 3.5 Knowledge.

Stage 1 Things to do with DotNetNuke©

Log in to your DotNetNuke© site as normal.





Go to the Host Page and then click on Module Definitions.




Click on the Create New Module Link.




Select New from the drop down list.


Find the green cross to the right of the Owner Folder drop down list and click it.
Fill in the folder name and then click the create folder link.
Find the green cross to the right of the Module Folder drop down list and click it.
Fill in the Module Folder Name and then click the create folder link.
Select the programming language you require by clicking the relevant radio button.
DotNetNuke© is written in VB but you can use C# if you are more comfortable. We are going to use VB this time.
In the file name field enter the file name View.ascx.
Enter a name for your module that is friendly e.g, EmailMe.
Add a description for what your control will do.
Click the Add test page link.
Click the Create Module link.



You will see that DotNetNuke© has added a test page to the menu and messaged you to say all is well.




Stage 2 Moving onto Visual Studio

Open Visual Studio.
Open the DotNetNuke© Project you created the module in.
Locate in the Solution Explorer the View.ascx that DotNetNuke© just created, it will be in the Desktop Modules Folder in the Folders you created in steps 5-8 above.




Delete the View.ascx and then re add it by right clicking on the folder and selecting add new, this will recreate the View.ascx with the required code behind file, don’t forget to tick the code behind box to create a separate code file.




Design the form layout as per a normal ASP.Net Contact form adding a submit button.
Ensure the Declaration is correct for the CodeFile and Inheritance it should look like this:

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="View.ascx.vb"
Inherits="DesktopModules_MyContactForm_Simple_Email_View" %>

Create an event handler for the button or image button you are using for submit.
Open the VB code behind file and alter the Inherits System.Web.UI.UserControl to InheritsDotNetNuke.Entities.Modules.PortalModuleBase.
In the Event Handler add the DotNetNuke SendMail method, As a minimum it should look like this:

DotNetNuke.Services.Mail.Mail.SendMail(Textural.Text, "email@xxxx.com", "", TextBoxSubject.Text, TextBoxMessage.Text, "", "", "", "", "", "")

If you require wrap the SendMail in a try catch block to catch errors when you test it, always good practise anyway and you should always do it.
Build the Page.
The module development is now complete.

Stage 3 Back to DotNetNuke

Go back to your DotNetNuke© site, log in if you are not already and then go to the Test Page that was created earlier.
Using the DotNetNuke menu look in the Add Module Drop Down List and locate the new module which should have the friendly name you gave it, in this case EmailMe.
Add the Module to the page as per normal.


Congratulations you have built and added a new DotNetNuke© module.


Problems?

Ensure that the email you used in the SendMail method is the email that is used in your DotNetNuke SMTP settings and is the Host email address otherwise your form will not work. In fact ensure all the emails you have in any DotNetNuke© settings are the same for everything as it ensures all the mail processes run smoothly.

You can use the Test link next to the SMTP settings in DotNetNuke© to see if you have it all set up ok and that your portal can actually send emails.
If there is nothing being sent, check your local SMTP server in IIS is configured correctly and also look in the mailroot folder in inetpub to see if there are queued emails.

Check your SMTP ports and check your ISP allows mail on port 25, if not change the port.


Download the Source Files



Copyright ©2011


Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 


Recent Posts

Google Analytics Not Working

Custom MailChimp Email Templates

Building a Simple Contact Form in DotNetNuke 5

Mobile Website Design Tips



Comments

Submit your website
Web Design Blog Ipswich - AnodisedBlue - AnodisedBlue Blog - Google Analytics Not Working
# SEO software


electronic cigarette