Geeks With Blogs
Matthew Cassell a windows developer writing asp .net web apps

Recently, on a project I was working on, we really wanted to allow users to build rich & dynamic pages. We wanted to be able to build building blocks from which user’s could customize upon. We wanted to be able to have user’s quickly design their own pages without having to worry about HTML. The solution? Webparts.

So off to work I set out, building a series of webparts such as a rich html webpart with a HTML Text Box as its custom designer. A rich content web part allowing the user to display flash, video, or a picture. A user information webpart. So you get the idea, a wide pallet allowing the user to do what they wanted to do.

Next I built a page to host these wonderful web parts, and allowed the user (if logged in) to add, remove, and customize them. It was beautiful, but not what we needed. What we needed was to allow the user to dynamically create pages. I discovered, that webparts by default are bound to the specific .aspx page they are created with. For instance, there would be no way to separate home.aspx?page=1 from home.aspx?page=2.

After some investigating, it turns out the easiest solution (that I found) was to inherit the System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider and override the LoadPersonalizationBlobs and SavePersonalizationBlob methods to get them to recognize the difference as shown below:

Public Class AdvancedSqlPersonalizationProvider

        Inherits System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider

 

        Public Overrides Function LoadPersonalizationState(ByVal webPartManager As System.Web.UI.WebControls.WebParts.WebPartManager, ByVal ignoreCurrentUser As Boolean) As System.Web.UI.WebControls.WebParts.PersonalizationState

            Return MyBase.LoadPersonalizationState(webPartManager, ignoreCurrentUser)

        End Function

        Protected Overloads Overrides Sub LoadPersonalizationBlobs(ByVal webPartManager As WebPartManager, ByVal path As String, ByVal userName As String, ByRef sharedDataBlob As Byte(), ByRef userDataBlob As Byte())

            If Not (System.Web.HttpContext.Current.Request("page") Is Nothing) Then

                MyBase.LoadPersonalizationBlobs(webPartManager, System.Web.HttpContext.Current.Request("page"), userName, sharedDataBlob, userDataBlob)

            Else

                MyBase.LoadPersonalizationBlobs(webPartManager, path, userName, sharedDataBlob, userDataBlob)

            End If

        End Sub

 

        Protected Overloads Overrides Sub SavePersonalizationBlob(ByVal webPartManager As WebPartManager, ByVal path As String, ByVal userName As String, ByVal dataBlob As Byte())

            If Not (System.Web.HttpContext.Current.Request("page") Is Nothing) Then

                MyBase.SavePersonalizationBlob(webPartManager, System.Web.HttpContext.Current.Request("page"), userName, dataBlob)

            Else

                MyBase.SavePersonalizationBlob(webPartManager, path, userName, dataBlob)

            End If

        End Sub

    End Class

We then use this as the data provider for the webparts. What this does is it provides a mechanism to seamlessly create dynamic pages, and have it all handed by the existing and stable webparts engine.  This, coupled with properly done URL Re-Writing means you can virtually eliminate the need for multiple .aspx pages on your site.

Posted on Sunday, May 13, 2007 8:25 PM | Back to top


Comments on this post: Building DotNetNuke Style Portals Using ASP .net 2.0 WebParts

# re: Building DotNetNuke Style Portals Using ASP .net 2.0 WebParts
Requesting Gravatar...
What are you setting ystem.Web.HttpContext.Current.Request("page") to equal? The webForm that the webpartManager is on?
Left by Dan on Apr 21, 2009 10:55 AM

# re: Building DotNetNuke Style Portals Using ASP .net 2.0 WebParts
Requesting Gravatar...
Any idea why this is not working?

Dim sUser As String = HttpContext.Current.Session("userid")
If sUser <> userName And sUser <> Nothing Then
userName = sUser
End If

MyBase.LoadPersonalizationBlobs(webPartManager, path, userName, sharedDataBlob, userDataBlob)

It throws this error

The specified display mode is currently disabled on this page. Make sure personalization is enabled for the current user.
Parameter name: value


Left by Bill on Apr 21, 2009 10:56 AM

Your comment:
 (will show your gravatar)


Copyright © Matthew Cassell | Powered by: GeeksWithBlogs.net