Jason Salas' WebLog

On-air and online: making people laugh, making people think, pissing people off

ASP.NET sites that kick ass

Pals with blogs

Podcasts I listen to

Working on Web Parts, C# 2.0 Generics...

Well, it took me long enough, but I've gotten here.  I've been working on different ideas for Web Parts...trying to develop some sort of anonymous personalization, mainly.  Basically, I'd like to give my users the ability to check out my site and reconfigure the physical layout of the different content areas, WITHOUT having to signup for membership.

Microsoft has said that such was possible before, but has since been taken out, most likely due to the fact that the SavePersonlizationData() method is now protected.

Still working on it, but this is essentially what is wrapped by the Page-level declaration “EnablePersonalization“:

WEB.CONFIG
=============
<system.web>
<anonymousIdentification enabled="true"/>
<personalization>
 <profile>
  <property name="StartPoint" type="System.Int32" defaultValue="1" allowAnonymous="true"/>
 </profile>
</personalization>
</system.web>


SOMEFILE.ASPX
=============
WebPartManager manager = WebPartManager.Current;

for(int i=0;i<manager.Zones.Count-1;i++)
{
 // get a reference to the current zone in which the current web part sits
 int currPosition = manager.Zones[i]; 
 
 WebPartCollection wpc = GetWebPartsForZone(manager.Zones[i]);
 for(int j=0;manager.wpc.Count-1;j++)
 {
  // get a reference to the current web part 
  int part = manager.wpc.WebParts[j];
  
  // get a reference to the default position set in the Profile object in web.config
  int defaultPosition = Profile.StartPoint;

  /*
   NOTE:
   ======
   This would probably work a lot better if somehow the web.cofig file could be read like a dictionary...that way,

each Profile property could be evaluated against each WebPart
  
  */
  
  // if the web part's current position is not the the default, then move it programmatically
  if(currPosition.CompareTo(defaultPosition) != 0)
  {
   // if there is a web part already placed at the beginning index of the web part zone, place it lower on the

control tree
   int index = 0;
   if(manager.wpc.WebParts[j])
   {
    index++;
   }
   manager.MoveWebPart(part,currPosition,index);
  }
 }
}

 

 

 

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required)