Register | Login
Thursday, August 28, 2008

Sections
  
About Us
  
Hosting Provided by Server Intellect
Partners
Downloads
  
 WWWCoder.com Resource Directory

 

ORDER TODAY!
Professional DotNetNuke ASP.NET Portals
Amazon.com now has the only DotNetNuke book you'll ever need. Written by the guys who brought you DotNetNuke, Shaun Walker, Patrick Santry, Joe Brinkman, Dan Caron, Scott McCulloch, Scott Willhite, and Bruce Hopkins. Order it now! .

Extending the DNN HTML Module
9/16/2003 8:48:52 AM

This code snippet covers extending the HTML module that comes with DotNetNuke. It will allow you to populate the InsertHTML drop down of the FreeTextBox control with links to other tabs within your portal as well as other modifications to the control to make content editing a bit easier.

The following is a quick tip for extending the HTML module that comes included in DotNetNuke 1.0.10.

DotNetNuke comes with some great content tools built right into the package. The HTML module has the FreeTextBox (FTB) control bundled in with it. The FreeTextBox control is an open source ASP.Net Web control that you can include in your projects, more information can be found on the www.revjon.com Website.

The Problem

For this particular code snippit I wanted to be able to extend the FTB to make it easier for my content editors to be able to apply DNN styles and insert links to other tabs within DNN. Another issue was FTB inserts absolute links when linking to internal documents and not relative links; this is fine if all you content editing is done on you production system, but in this particular case we were first building our content on a test server and eventually wanted to publish it to another domain in production.

The Solution

The solution to this was rather simple thanks to the FTB control providing several public methods and properties that we can modify. We created a new method within the EditHTML.ascx.vb control that is located in the ~/DesktopModules/HTML directory within DNN, and called this method PrepHTMLTextBox. This method will change some properties for our FTB control and populate the InsertHTML drop down with links to other tabs that can be inserted into the HTML document simply by selecting the tab from the drop down box.

The Code

Private Sub PrepHTMLTextbox()
   With ftbDesktopText
      Dim aryMenuNames As String()
      Dim aryMenuList As String()
      Dim tmpNames As String
      Dim tmpList As String
      Dim objArts As New AdminDB
      'now call the GetTabs method to get all tabs for this
      'portal, then we'll insert them into a string array
      'and populate the drop down list of the FTB control.
      Dim dr As SqlDataReader = objArts.GetTabs(PortalId)
      Dim tmpLink As String
      If dr.Read Then
         tmpNames = dr("TabName") & ";"
         tmpLink = "<a href=""" & IIf(Request.ApplicationPath = "/", _
                Request.ApplicationPath, Request.ApplicationPath & "/") & _
                        "DesktopDefault.aspx?tabid=" & dr("TabID") & """>" & _
                dr("TabName") & "</a>"
         tmpList = tmpLink & ";"
         Do While dr.Read
             tmpNames = tmpNames & dr("TabName") & ";"
             tmpLink = "<a href=""" & IIf(Request.ApplicationPath = "/", _
                Request.ApplicationPath, Request.ApplicationPath & "/") & _
                                                "DesktopDefault.aspx?tabid=" & _
                dr("TabID") & """>" & dr("TabName") & "</a>"
             tmpList = tmpList & tmpLink & ";"
         Loop
         tmpNames = Left(tmpNames, Len(tmpNames) - 1)
         tmpList = Left(tmpList, Len(tmpList) - 1)
         aryMenuNames = Split(tmpNames, ";")
         aryMenuList = Split(tmpList, ";")
         .InsertHtmlMenuTitle = "Insert Links to Articles"
         .InsertHtmlMenuNames = aryMenuNames
         .InsertHtmlMenuList = aryMenuList
         .RemoveServerNameFromUrls = True
      End If
      'create another array to populate the styles drop down.
      Dim aryStyles As String() = {"Head", "SubHead", "SubSubHead", _
                 "Normal", "NormalRed", "NormalBold"}
      .StyleMenuList = aryStyles
      .StyleMenuNames = aryStyles
   End With
End Sub

If you look at the code above, you can see what we did here to extend the control. First we declared some variables to hold our values. Then we called the method provided by the DNN core framework called "GetTabs" this will return a Data Reader with the tabs for our particular portal. We then build some href tags with the returned data which eventually will populate the drop down list. When someone selects an item from the drop down list, it will insert the html into the document where they are currently in focus.

After populating the control, we then set the RemoveServerNameFromUrls to true in order to provide relative linking for our links. And finally we created a simple array to grab our DNN styles and populate the styles drop down in the control.

Now once the method is created we just place a call to the method within the Page_Load event of the EditHTML.ascx.vb class:

Private Sub Page_Load(ByVal sender As System.Object, _
       ByVal e As System.EventArgs) Handles MyBase.Load
   ' Obtain PortalSettings from Current Context
   Dim _portalSettings As PortalSettings = CType(HttpContext.Current.Items("PortalSettings"), _
          PortalSettings)
		::
		::
		::OMITTED CODE
		::
          End If
        End If
      End If
   End If
   PrepHTMLTextbox()
End Sub

Save your changes and then recompile the DNN project. You should now be able to insert the links to your tabs from within the editor, links are relative, and styles will be populated.


Page Options:
format for printing  Format for Printer
email article  Email Page
add to your favorites   Add to Favorites
How would you rate the quality of this content?
Poor - - Excellent
Comments?
Overall Rating:
Comments Left:
Left on 12/13/2007 6:42:33 PM by Anonymous
Comments: Best sites for you!:
http://airfare1.white.prohosting.com
http://lumberwood.tripod.com
http://zipo3.hit.bg
http://zipo2.hit.bg
http://balancecred.bravehost.com

End ^) Goodbye.
Left on 10/24/2007 11:04:28 PM by Anonymous
Comments:
Left on 5/22/2004 1:28:35 AM by Anonymous
Comments: the styles enhancement is great.  the page linking would also be great except that it doesn't appear to handle a virtual directory work environment scenario (where http://localhost/DNN/desktopdefault.aspx?tabid=xx is reduced to DNN/desktopdefault.aspx?tabid=xx which is not going to transfer to a production machine as mentioned in the precipitating scenario without further massaging.)
Left on 12/10/2003 3:58:35 AM by Anonymous
Comments: This is what I'm searching for! thanks!
Left on 9/26/2003 7:23:47 AM by Anonymous
Comments: Nice ENH
  

 Latest Articles
  

 Latest News
  

 

Spotlight
Syndication

 


 


Digg This
 


DotNetNuke Platinum Benefactor

  
 

 Terms Of Use | Privacy Statement
 Copyright 2008 - Santry Technology Solutions, Box 172, Girard, PA 16417, (814) 774-0970