I want to dynamically add some WebParts when a user logs on--which I have done, and it works. However, I only want to do this on the FIRST logon. I thne want users to able to delete the parts and add whatever else they want from the catalog.
The thing is, whenever someone logs in, it keeps loading that same WebPart, and I DON'T want that.
How can I go about doing this? I have done a BUNCH of research in the past few days, and tried a few things, but I am stuck now.
Please help!
Here is some code:
My Class file:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace riv
{
public class rivWebPart : WebPartManager
{
public void SetDirty()
{
// Invoke the protected SetPersonalizationDirty method
SetPersonalizationDirty();
}
}
}
My Master Page Code Behind
public partial class StandardProvider : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
Control uc = this.LoadControl(@"\webparts\moviesDotCom.ascx");
uc.ID = "wp1";
GenericWebPart wp1 = rivwpManager.CreateWebPart(uc);
rivwpManager.AddWebPart(wp1, zoneMiddle, 1);
rivwpManager.SetDirty();
}
I check all WebPartZones to see if there are WebParts in any of the zones. If all zones are empty, I take it to mean this is the first logon, and add the initial set of WebParts by code.
ddicecca
Member
19 Points
98 Posts
Load WebParts ONLY on First Logon
May 10, 2007 04:03 PM|LINK
Hey all,
I want to dynamically add some WebParts when a user logs on--which I have done, and it works. However, I only want to do this on the FIRST logon. I thne want users to able to delete the parts and add whatever else they want from the catalog.
The thing is, whenever someone logs in, it keeps loading that same WebPart, and I DON'T want that.
How can I go about doing this? I have done a BUNCH of research in the past few days, and tried a few things, but I am stuck now.
Please help!
Here is some code:
My Class file:
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; namespace riv { public class rivWebPart : WebPartManager { public void SetDirty() { // Invoke the protected SetPersonalizationDirty method SetPersonalizationDirty(); } } }ddicecca
Member
19 Points
98 Posts
Re: Load WebParts ONLY on First Logon
May 10, 2007 09:45 PM|LINK
Anyone? Hello? Anyone know?
rcport
Member
49 Points
20 Posts
Re: Load WebParts ONLY on First Logon
May 10, 2007 09:52 PM|LINK
ddicecca
Member
19 Points
98 Posts
Re: Load WebParts ONLY on First Logon
May 10, 2007 11:01 PM|LINK
Would you share a little more please? Perhaps a code example in C#?
Thank you,
D
rcport
Member
49 Points
20 Posts
Re: Load WebParts ONLY on First Logon
May 11, 2007 02:23 PM|LINK
protected void Page_PreRender (object sender, EventArgs e)
{
// WebPartZone1, 2, 3 are WebPartZones on my page
if (WebPartZone1.WebParts.Count == 0 &&
WebPartZone2.WebParts.Count == 0 &&
WebPartZone3.WebParts.Count == 0)
{
// Add default Web Part modules here
}
}
ddicecca
Member
19 Points
98 Posts
Re: Load WebParts ONLY on First Logon
May 11, 2007 02:45 PM|LINK
You rock, dude! That works, and it's SO SIMPLE!
Thanks again!
Cheers!