I am advocating a few things with my tutorial:
|
|||
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" |
|||
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: |
|||
|
|||
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: |
|||
|
|||
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: |
|||
|
|||
However, in “ViewGuestBook.ascx.vb” I have this:
|
|||
|
|||
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: | |||
|
|||
BACK
|
|
||
DotNetNuke® is a registered trademark of Perpetual Motion Interactive Systems Inc.