469,898 Members | 1,626 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

WebPart events not triggered upon first logon

I am involved with development of a Portal solution using ASP.NET 2.0
and WebParts. The WebParts framework use the default personalization
providers, and the personalization data thus ends up in the aspnetdb
database (which we have placed on a proper SQL Server, not SQL Server
Express).

Everything works like a charm, with the following exception:

New users in the system have to press links or buttons twice upon their
first logon to the solution in order for the events to fire. The first
time the links or buttons are fired there is a postback, but the event
is not triggered. The second time it works fine.

The WebParts are added dynamically during Page_Load (see code below),
so the reason the events are not firing the first time is most likely
because the events have not been properly wired-up the first time the
page is posted back. At this time there is no record in the asbnetdb
for the user, i.e. the user personalization has not yet been persisted.

However, when the page is rendered after the first click the
personalization data for the user is persisted (with the
aspnet_PersonalizationPerUser_SetPageSettings stored procedure). Thus,
when the page is loaded the second time the web part is instantiated by
the web parts framework, and the events are wired up as they should.

The problem has been isolated in a testpage containing a
WebPartManager, a WebPartZone, and one WebPart that is added
dynamically in Page_Load.

Perhaps the problem could be solved if we could force the web parts
framework to perform the aspnet_PersonalizationPerUser_SetPageSettings
after the first initial rendering of the page, but the best way would
be to have the events wire-up done correctly. Also, I cannot see that
there is any way of forcing the framework to perform the
aspnet_PersonalizationPerUser_SetPageSettings procedure.

Any help to solve this would be appreciated.

The code-behind for this is shown here:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;

/// <summary>
/// To reproduce problem with events not firing first time:
///
/// 1. Delete all personalization info for the user from the database
/// 2. Open the page in the browser and minimize the WebPart.
/// The event is not triggered.
/// </summary>
public partial class WebPartTest2 : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
WebPartManager mgr = WebPartManager1;
// only add the webpart if it has not already
// been added by the web parts framework
if (mgr.WebParts.Count == 0)
{
Calendar cal = new Calendar();
cal.ID = "cal1";
GenericWebPart calWebPart = mgr.CreateWebPart(cal);
mgr.AddWebPart(calWebPart, WebPartZone1, 1);
}
}
}
------------------------------------------
Paal Berggreen
www.makingwaves.no
M A K I N G W A V E S
Vaskeriet
Christian Krohgs gate 60
N-0186 Oslo

Apr 18 '06 #1
5 1627
DWS
Paal,
Sorry I can't help with two click problem but I offer assistance with one of
these two built into ASP.Net 2.0 solutions for adding webparts to your a
webpage.

I can help with adding webparts to the page at runtime with the
declaritivecatalog or importcatalog. If your interested reply to group or
start new thread.

I can help with entersharedstate where one person adds the webpart to the
page for everyone. If your interested reply to group or start new thread.

Good Luck
DWS

"Paal Berggreen" wrote:
I am involved with development of a Portal solution using ASP.NET 2.0
and WebParts. The WebParts framework use the default personalization
providers, and the personalization data thus ends up in the aspnetdb
database (which we have placed on a proper SQL Server, not SQL Server
Express).

Everything works like a charm, with the following exception:

New users in the system have to press links or buttons twice upon their
first logon to the solution in order for the events to fire. The first
time the links or buttons are fired there is a postback, but the event
is not triggered. The second time it works fine.

The WebParts are added dynamically during Page_Load (see code below),
so the reason the events are not firing the first time is most likely
because the events have not been properly wired-up the first time the
page is posted back. At this time there is no record in the asbnetdb
for the user, i.e. the user personalization has not yet been persisted.

However, when the page is rendered after the first click the
personalization data for the user is persisted (with the
aspnet_PersonalizationPerUser_SetPageSettings stored procedure). Thus,
when the page is loaded the second time the web part is instantiated by
the web parts framework, and the events are wired up as they should.

The problem has been isolated in a testpage containing a
WebPartManager, a WebPartZone, and one WebPart that is added
dynamically in Page_Load.

Perhaps the problem could be solved if we could force the web parts
framework to perform the aspnet_PersonalizationPerUser_SetPageSettings
after the first initial rendering of the page, but the best way would
be to have the events wire-up done correctly. Also, I cannot see that
there is any way of forcing the framework to perform the
aspnet_PersonalizationPerUser_SetPageSettings procedure.

Any help to solve this would be appreciated.

The code-behind for this is shown here:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;

/// <summary>
/// To reproduce problem with events not firing first time:
///
/// 1. Delete all personalization info for the user from the database
/// 2. Open the page in the browser and minimize the WebPart.
/// The event is not triggered.
/// </summary>
public partial class WebPartTest2 : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
WebPartManager mgr = WebPartManager1;
// only add the webpart if it has not already
// been added by the web parts framework
if (mgr.WebParts.Count == 0)
{
Calendar cal = new Calendar();
cal.ID = "cal1";
GenericWebPart calWebPart = mgr.CreateWebPart(cal);
mgr.AddWebPart(calWebPart, WebPartZone1, 1);
}
}
}
------------------------------------------
Paal Berggreen
www.makingwaves.no
M A K I N G W A V E S
Vaskeriet
Christian Krohgs gate 60
N-0186 Oslo

Apr 18 '06 #2
Hi! Thanks for the tips. Unfortunately this is not the area that we
need help for, but thanks anyway :-)

-Paal

Apr 18 '06 #3
Hi Paal,

Semi-qualified guess:
There is a security restriction preventing personalization to be
updated on get-requests.
when reaching page load after the first minimize click
mgr.WebParts.Count is zero since personalization has been prevented.
So, the part is recreated by your own code in page_load, but this time
personalization is persisted correctly since it is done in a postback.
After the second minimize click occurs the webpart framework creates
the web part from the personalization data hence the postback event can
be handled since the controlId of the part will be the same.

I think what you want to accomplish can be done by overriding
GetInitialWebParts of the webpartzone. It is a method that is used for
populating the zone with static webparts.

Good Luck again!

..f

Apr 20 '06 #4
You might (just for giggles) try moving the method from Page_Load to
Page_Init and doing a mgr.EnsureChildControls() before you start adding
controls.

(I don't have a way to test this problem right this second, however, you may
force things to get wired up correctly on the first pass if it's in at
init.)

Rob

--
Robert L. Bogue, MS MVP, MCSE, MCSA:Security, Etc.
Blog: http://www.thorprojects.com/blog
"Paal Berggreen" <pa**@berggreen.as> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
I am involved with development of a Portal solution using ASP.NET 2.0
and WebParts. The WebParts framework use the default personalization
providers, and the personalization data thus ends up in the aspnetdb
database (which we have placed on a proper SQL Server, not SQL Server
Express).

Everything works like a charm, with the following exception:

New users in the system have to press links or buttons twice upon their
first logon to the solution in order for the events to fire. The first
time the links or buttons are fired there is a postback, but the event
is not triggered. The second time it works fine.

The WebParts are added dynamically during Page_Load (see code below),
so the reason the events are not firing the first time is most likely
because the events have not been properly wired-up the first time the
page is posted back. At this time there is no record in the asbnetdb
for the user, i.e. the user personalization has not yet been persisted.

However, when the page is rendered after the first click the
personalization data for the user is persisted (with the
aspnet_PersonalizationPerUser_SetPageSettings stored procedure). Thus,
when the page is loaded the second time the web part is instantiated by
the web parts framework, and the events are wired up as they should.

The problem has been isolated in a testpage containing a
WebPartManager, a WebPartZone, and one WebPart that is added
dynamically in Page_Load.

Perhaps the problem could be solved if we could force the web parts
framework to perform the aspnet_PersonalizationPerUser_SetPageSettings
after the first initial rendering of the page, but the best way would
be to have the events wire-up done correctly. Also, I cannot see that
there is any way of forcing the framework to perform the
aspnet_PersonalizationPerUser_SetPageSettings procedure.

Any help to solve this would be appreciated.

The code-behind for this is shown here:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;

/// <summary>
/// To reproduce problem with events not firing first time:
///
/// 1. Delete all personalization info for the user from the database
/// 2. Open the page in the browser and minimize the WebPart.
/// The event is not triggered.
/// </summary>
public partial class WebPartTest2 : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
WebPartManager mgr = WebPartManager1;
// only add the webpart if it has not already
// been added by the web parts framework
if (mgr.WebParts.Count == 0)
{
Calendar cal = new Calendar();
cal.ID = "cal1";
GenericWebPart calWebPart = mgr.CreateWebPart(cal);
mgr.AddWebPart(calWebPart, WebPartZone1, 1);
}
}
}
------------------------------------------
Paal Berggreen
www.makingwaves.no
M A K I N G W A V E S
Vaskeriet
Christian Krohgs gate 60
N-0186 Oslo

May 26 '06 #5
Actually, I found the solution myself, and as is usually the case the
solution is quite simple, when you know where to look.

The solution is to call WebPartManager.SetDirty() after the web parts
have been dynamically added; this forces the web part framework to
persist the personalization data before the page result is returned to
the user.

Everything now works like a charm! :-)
-Paal

Jun 13 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by DC Gringo | last post: by
2 posts views Thread by Heiko Vainsalu | last post: by
3 posts views Thread by Stampede | last post: by
1 post views Thread by Abel Chan | last post: by
3 posts views Thread by Jav | last post: by
reply views Thread by jademoon | last post: by
4 posts views Thread by Don | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.