Monday, September 12, 2005

Configure WebParts as a menu in the Masterpage!!

For long time we have been trying to use webparts in our application's menu. Something like what My MSN does. But an interesting observation is that all the web part links to pages that open up on seperate pages. But in our application: webparts are located in the master pages and all the links in the webparts are supposed to open up in the content pages, we have may webparts according to the different modules and each webpart contains serveral links pertaining to that module. So far so good; no probs. But then comes the moving around of webparts. Once the user moves around the webpart menus according to his own convenience, it should stay the same for all pages! But we found out that the webpart only stays the same for the particular aspx page that it was arranged for!! But what we are trying to do is to arrange the menu for all the pages for that particular user!
This kinda seemed impossible to achieve as the webparts are located in the masterpages and the personlization uses URL of the content page as the personlzation key!
So wondering how to achieve this? This is how my colleague got it to work!!!
You need to overwrite "System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider" class with your own custom class. You need to perform a small hack here when you get or set the path. You can now put the web part in the master pages, drag, minimize, etc and when you navigate to a different page, the same arragement of webparts will be displayed. You just need to ensure the web.config is pointing to this custom class for personalization.
Custom SqlPersonalization:public class CustomSqlPersonalizationProvider : SqlPersonalizationProvider{
private string GetPath{get{return "default.aspx";}}
protected override void LoadPersonalizationBlobs(WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob){base.LoadPersonalizationBlobs(webPartManager, this.GetPath, userName, ref sharedDataBlob, ref userDataBlob);}
protected override void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, byte[] dataBlob){base.SavePersonalizationBlob(webPartManager, this.GetPath, userName, dataBlob);}
protected override void ResetPersonalizationBlob(WebPartManager webPartManager, string path, string userName){base.ResetPersonalizationBlob(webPartManager, this.GetPath, userName);}}This solution has also been published in the forums

Referral Link
Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?

© Copyright 2005, Rohan Thomas
This Blog contains findings that are self-explored and expressions that are self-evoked. They are by no meanss representions of my employer's view.