aDEFWEBSERVER
Los Angeles, CA *  Webmaster@ADefWebserver.com

Creating a DotNetNuke® Module For absolute beginners!
For DotNetNuke Version 4 - Page 7 (Page 6)

I am advocating a few things with my tutorial:

  • Show how easy it is to create DotNetNuke modules
  • Show that you don’t need external tools other than Visual Web Developer and the Website Starter Templates
  • Show that using Object Data Sources and Generics reduce the code massively
 
 

Object Data Sources in DotNetNuke explained:

 Using the “GuestBook_Update” method as an example, we can see that it is called by the “EditGuestBook.ascx” control. In that control, we have this code for the Object Data Source: 

 
<asp:ObjectDataSource ID="ObjectDataSource_Tasks" runat="server" DataObjectTypeName="YourCompany.Modules.GuestBook.GuestBookInfo"
DeleteMethod="GuestBook_Delete" InsertMethod="GuestBook_Insert" OldValuesParameterFormatString="original_{0}"
OnInit="Page_Load" SelectMethod="GuestBook_GetAll" TypeName="YourCompany.Modules.GuestBook.GuestBookController"
UpdateMethod="GuestBook_Update">
<SelectParameters>
<asp:Parameter DefaultValue="00" Name="ModuleId" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
The “GridView”, that the user uses to input and retrieve data, is simply bound to this control. Notice the “DataObjectTypeName="YourCompany.Modules.GuestBook.GuestBookInfo". This tells the Object Data Source that the “GuestBookInfo” object will be used to pass the parameters.  
 

This is just a simple class. However, you could put business logic in it if you desired so you would have complete control of your parameters in an encapsulated proper OOP design. This is why you would want to use Object Data Sources rather than SQL Data controls. With Object Data Sources, you retain full n-tier design. You have full control over the data from beginning to end.

Now notice the “TypeName="YourCompany.Modules.GuestBook.GuestBookController“. This indicates the class that will be handling the “Select”, “Update”, “Insert”, and “Delete” methods (also note, I have chosen to make this a static class for further optimization).  

Next, notice the “UpdateMethod="GuestBook_Update”“. This indicates that the “GuestBook_Update” method in the “GuestBookController” class will handle the updates.

 

In the “GridView” the person clicks “Update”, and because it is bound to the Object Data Source control, the Object Data Source control puts the parameters passed to it from the “GridView” into the “GuestBookInfo” object and passes that object to the “GuestBook_Update” method of the “GuestBookController” class: 

 

 

<DataObjectMethod(DataObjectMethodType.Update)> _
  Public Shared Sub GuestBook_Update(ByVal objTest As GuestBookInfo)
    DataProvider.Instance.YourCompany_GuestBook_Update(objTest.ID,   objTest.Name, objTest.Email, objTest.Message, objTest.DateEntered)
  End Sub

This method receives the “GuestBookInfo” class, opens up the class and passes each parameter to the Data Access Layer.

You will notice the “GuestBookInfo” object is used for each method in the “GuestBookController” class except for the “Select” method:

 

 

<DataObjectMethod(DataObjectMethodType.Select)> _
  Public Shared Function GuestBook_GetAll(ByVal ModuleId As Integer) As List(Of   GuestBookInfo)
    Return CBO.FillCollection(Of GuestBookInfo)(DataProvider.Instance().YourCompany_GuestBook_GetAll(ModuleId))
  End Function

In the “Select” method, it is passed a “ModuleId” parameter and it returns a “GuestBookInfo” object.

This brings us to the other thing I figured out that hopefully will help those using Object Data Sources with DotNetNuke. There is a problem of grabbing the current “ModuleId”.

 

This is a very important value that is exposed by the DotNetnuke core code. This value tells you which instance of the module you are working with. This is important because a person can place 20 instances of you module on a single page. You can’t have them click a button on one instance of the module and return data from another instance of the module.

 

You can see my solution in “ViewGuestBook.ascx” and “ViewGuestBook.ascx.vb”. In “ViewGuestBook.ascx”, in the Object Data Source control, I indicate the “ModuleId” parameter as a “Select” parameter that I will be passing to the “Select” method:

 

<SelectParameters>
<asp:Parameter DefaultValue="00" Name="ModuleId" Type="Int32" />
</SelectParameters>

However, in “ViewGuestBook.ascx.vb” I have this:

 

 

Protected Sub SetModuleId(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs) Handles ObjectDataSource_Tasks.Selecting
      e.InputParameters("ModuleId") = ModuleId.ToString
End Sub

This event fires when the “Select” event is called in the Object Data Source control, but before the control passes the value to the “Update” method in the “GuestBookController” class. This allows me to pass the “ModuleId” to the “GuestBookController” class (and on to the stored procedure so it returns the proper data).

Here is the point, after I create my “GuestBookInfo” class and my “GuestBookController” class, I am able to drag and drop the Object Data Source and GridView controls using the visual designer in Visual Studio. I am able to right click on them and configure everything but the 3 lines of code for the “SetModuleId “ method.

Once you have done this one or two times you can do it in less than a minute. I am able to make a DotNetNuke module almost as fast as a normal program. This simply was not the case before.

 

The major underrated advancement the core made with DotNetNuke 4 was to alter the DotNetNuke framework to make module development much easier. In the past, it was so hard for people to learn how to develop modules using the ASP.NET 1.1 method. The configuration needed was a nightmare.

All that has changed. We will see more developers releasing more modules and the price of modules on snowcovered.com will fall and the quality of the best modules will improve.

 
   

The tutorial is complete.

 
If you find any errors or omissions please email me at webmaster@adefwebserver.com  
About the Author:  
PatrickSantry.jpg

Michael Washington is a Website developer and an ASP.NET, C#, and Visual Basic programmer. He has extensive knowledge in process improvement, billing systems, and credit card transaction processing. He has been involved with DotNetNuke for nearly 3 years and has worked on the DotNetNuke Data Access Layer enhancements. He is the author of numerous DotNetNuke modules and tutorials. He is one of the founding members of the Southern California DotNetNuke Users group (http://socaldug.org). He has a son, Zachary and resides in Los Angeles with his wife Valerie.

 
 
   
   
   
   
   
   
   
   
   
   
   

BACK
 

 

   
   
   

 

DotNetNuke MarketPlace

(C) by Michael Washington - ADefWebserver.com - Webmaster@ADefWebserver.com

DotNetNuke® is a registered trademark of Perpetual Motion Interactive Systems Inc.