Summary


DotNetNuke Helper Functions

In the previous code samples, you may have noticed several functions provided by the DotNetNuke core framework to ease your module development. These helper functions consist of error handling and URL navigation. This section provides some quick examples on what these functions do and how to use them in your own modules. More detail is provided in Chapter 8, but this section reviews common methods that were used in the examples in this chapter.

Error Handling

If you've been developing ASP.NET for any length of time, you've probably seen the yellow error dump on a web page when something goes wrong. This isn't a very nice sight for your users to see, and sometimes it displays a little more information about your application than you would like. Sometimes you don't even realize there is a problem. You could write your own error-handling routines, but with DotNetNuke you don't have to. The core framework provides module developers with the ability to check a logged-on user's security level, and display an appropriate error based on who is logged on. For example, an administrator can be presented with a little bit more detail about what specifically erred out, and average users can just be presented with a friendly error informing them that something is wrong. In addition, with the Logging Provider in DotNetNuke, you can view a log of the errors that occurred within a timeframe. This ensures you can see what has been happening with your portal and any errors your modules may have raised.

In this chapter, the code examples call the ProcessModuleLoadException method. For example:

 Try     'some logic Catch exc As Exception     ProcessModuleLoadException(Me, exc) End Try 

By using this method, you raise the error to DotNetNuke built-in error handling. To view any errors, logon as an admin or host-level account, and select Admin ê Log Viewer. This brings up the Log Viewer screen. Errors are presented with a red entry by default. Just double-click the entry to view the error information.

Navigation URLs

Also covered in the sample code was the use of NavigateURL and EditURL. These provide two major functions: to load the appropriate control based on the key being passed to the function, and to support for friendly URLs in your module. Friendly URLs allow your module to eliminate the need to pass query strings in the URL. By using friendly URLs, you make it easier for spiders to spider your site, and it is an overall easier method to display and remember URLs to various pages in your site. For example, instead of using something like http://www.dotnetnuke.com/default.aspx?tabid=233 to navigate to a page within a portal, friendly URLs would provide you with http://www.dotnetnuke.com/defaultaspx?tabid/233/default.aspx as a path to the page. You can find more about the friendly URLs interface in Chapter 8.

NavigateURL provides you with the ability to load the appropriate control. This function is provided by DotNetNuke.Common.Globals.NavigateURL, located within the Globals.vb file in the <approot>\ components\shared\ directory in the DotNetNuke solution. This method accepts a TabID, which is the unique identifier of a page in your portal; ControlKey, which is the unique key you defined when you configured your module definition and identifies which user control to load for the module; and AdditionalParameters, which is for additional parameters. The additional parameters are a string array of the query string parameters you may need to pass in the URL. By using AdditionalParameters, you can easily implement friendly URLs for your module because DotNetNuke converts the string array to a directory structure to be displayed in the URLs.

For example, the following code snippet sets the NavigateURL property of a link button control using the DotNetNuke.Common.Globals.NavigateURL method:

 hypRegister.NavigateUrl = NavigateURL(PortalSettings.ActiveTab.TabID, "Edit", _     "mUser Accounts").ModuleID, "Userpara">The ID of the currently active page is passed to the URL, and the control you want to load is the control with the Edit key. In addition, you pass several parameters for the control such as the Module ID and current User ID.

In addition to the features provided by the NavigateURL method, EditURL is another function for building navigation for your module. It is provided by PortalModuleBase. This method does not accept a Tab ID value because it assumes it is being used for the module instance currently in use. For example, if you list a record set and you want to edit a particular item, you would pass the key of ItemID and then the value. The EditURL function would pass the information to the Edit control:

 <asp:HyperLink  NavigateUrl='<%# EditURL("ItemID", image from book DataBinder.Eval(Container.DataItem,"ItemID")) %>' Visible="<%# IsEditable %>" image from book runat="server"><asp:Image  ImageUrl="~/images/edit.gif" image from book Visible="<%# IsEditable %>" AlternateText="Edit" runat="server" /></asp:HyperLink> 

In this example, you're listing the events in a view user control and displaying an edit link to the user if he or she has edit permissions using the IsEditable Boolean value.




Professional DotNetNuke 4.0 (c) Open Source Web Application Framework for ASP. NET 4.0
Professional DotNetNuke 4: Open Source Web Application Framework for ASP.NET 2.0 (Programmer to Programmer)
ISBN: 0471788163
EAN: 2147483647
Year: 2006
Pages: 182

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net