473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Page Load called twice!

Hi,

Hmmm, a strange one for me, but hopefully not for others...

I have a base page which has

virtual protected void PageLoadEvent(object sender, System.EventArgs e){}

In the Page_Load method I call this

PageLoadEvent(sender, e);

In all the forms that inherit from it I have a protected override of
PageLoadEvent method which does the necessary for that particular form,
nothing too complex there, what is strange however is that one of the forms
which is a summary page has a datagrid which has hyperlinks in, and if I
click on one of these links it goes to a 'info breakdown page' driven by a
parameter. Although there is no Page_Load method in the 'info breakdown
page' as it is replaced by the PageLoadEvent method, this method gets called
once independently, and then again through the base page Page_Load event
method.

The way I proved this was to put a breakpoint in both the Page_Load event of
the Base Page, and one in the 'info breakdown page' PageLoadEvent method.
So then I click the hyperlink on the summary page, and it immediately stops
in PageLoadEvent on the 'info breakdown page', and then if you F5 it, it
stops in the base page Page_Load method code, which of course calls the
PageLoadEvent of the 'info breakdown page'.

This isn't the case for the other pages, and there only difference is that
the 'info breakdown page' is accessed/initiated by a hyperlink.

Any ideas anyone?
cheers in advance
Colin B
Nov 18 '05 #1
2 6388
Hi Colin,

Check the setting of AutoEventHookup on the page. If you're using CodeBehind
pages you generally don't want this as the CodeBehind page automatically
generates the OnLoad() event hookup.

Also if your form is inherited and your event hookups in the base class (in
InitializeComponent) you will end up hooking the eventhandler multiple times
and so it fires more than once. The solution there is to remove the OnLoad
code manually in the implementation level of the form.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/webblog/
----------------------------------
Making waves on the Web
"Colin Basterfield" <co**************@hotmail.com> wrote in message
news:uh**************@TK2MSFTNGP11.phx.gbl...
Hi,

Hmmm, a strange one for me, but hopefully not for others...

I have a base page which has

virtual protected void PageLoadEvent(object sender, System.EventArgs e){}

In the Page_Load method I call this

PageLoadEvent(sender, e);

In all the forms that inherit from it I have a protected override of
PageLoadEvent method which does the necessary for that particular form,
nothing too complex there, what is strange however is that one of the forms which is a summary page has a datagrid which has hyperlinks in, and if I
click on one of these links it goes to a 'info breakdown page' driven by a
parameter. Although there is no Page_Load method in the 'info breakdown
page' as it is replaced by the PageLoadEvent method, this method gets called once independently, and then again through the base page Page_Load event
method.

The way I proved this was to put a breakpoint in both the Page_Load event of the Base Page, and one in the 'info breakdown page' PageLoadEvent method.
So then I click the hyperlink on the summary page, and it immediately stops in PageLoadEvent on the 'info breakdown page', and then if you F5 it, it
stops in the base page Page_Load method code, which of course calls the
PageLoadEvent of the 'info breakdown page'.

This isn't the case for the other pages, and there only difference is that
the 'info breakdown page' is accessed/initiated by a hyperlink.

Any ideas anyone?
cheers in advance
Colin B

Nov 18 '05 #2
Hi Rick,

It took a few minutes for the penny to drop reading your reply, and now I
see what you mean, I don't need this.Load setting to anything in the forms
that inherit the base because that will call the PageLoadEvent method. In
my child forms I had that set to:

this.Load += new System.EventHandler(this.PageLoadEvent);

which of course would cause it to be called twice!

I took this line out, and voila, it only gets called once. The reason I
didn't spot it was that it appeared like it was only doing it for the form
that was initiated from the hyperlink because that was the only page that
generated dynamic controls, whereas the others only filled some labels up
text, so it only overwrote the second time around!

uh duh, I should have known that!
Thanks for your help!
Cheers
Colin

"Rick Strahl [MVP]" <ri********@hotmail.com> wrote in message
news:OP**************@tk2msftngp13.phx.gbl...
Hi Colin,

Check the setting of AutoEventHookup on the page. If you're using CodeBehind pages you generally don't want this as the CodeBehind page automatically
generates the OnLoad() event hookup.

Also if your form is inherited and your event hookups in the base class (in InitializeComponent) you will end up hooking the eventhandler multiple times and so it fires more than once. The solution there is to remove the OnLoad
code manually in the implementation level of the form.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/webblog/
----------------------------------
Making waves on the Web
"Colin Basterfield" <co**************@hotmail.com> wrote in message
news:uh**************@TK2MSFTNGP11.phx.gbl...
Hi,

Hmmm, a strange one for me, but hopefully not for others...

I have a base page which has

virtual protected void PageLoadEvent(object sender, System.EventArgs e){}
In the Page_Load method I call this

PageLoadEvent(sender, e);

In all the forms that inherit from it I have a protected override of
PageLoadEvent method which does the necessary for that particular form,
nothing too complex there, what is strange however is that one of the forms
which is a summary page has a datagrid which has hyperlinks in, and if I
click on one of these links it goes to a 'info breakdown page' driven by a parameter. Although there is no Page_Load method in the 'info breakdown
page' as it is replaced by the PageLoadEvent method, this method gets

called
once independently, and then again through the base page Page_Load event
method.

The way I proved this was to put a breakpoint in both the Page_Load event of
the Base Page, and one in the 'info breakdown page' PageLoadEvent

method. So then I click the hyperlink on the summary page, and it immediately

stops
in PageLoadEvent on the 'info breakdown page', and then if you F5 it, it stops in the base page Page_Load method code, which of course calls the
PageLoadEvent of the 'info breakdown page'.

This isn't the case for the other pages, and there only difference is that the 'info breakdown page' is accessed/initiated by a hyperlink.

Any ideas anyone?
cheers in advance
Colin B


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: mart | last post by:
I am experiencing a weird problem with some buttons on my webpage. The page_load is executing twice when a button is clicked. If I replace the button for a Linkbutton the page_load only loads...
7
by: Goober | last post by:
I have a page that receives a session variable from the default.aspx. On Page load, the code in Page load gets executed twice. So far, no problem. It sets the session variable each time,...
2
by: Samy | last post by:
Hi There, I have a user control with buttons on it which I use on a aspx page (parent page). On a button click, a modal dialog(aspx page) opens up and the user enters some info in the modal dialog...
3
by: Imran Aziz | last post by:
Hello All, I have a search text and button that post data and my button handler filters the repeater control. However when the button is clicked the first time. The page_load event is being called...
8
by: MaryA | last post by:
I have an aspx page that loads twice inspite of using the IsPostBack i removed all controls from the page and still the page_load event is called twice I appriciate any help coz i have lost...
9
by: mosscliffe | last post by:
I am sorry but I am all very new and slow at understanding all this ASP.NET2. I found some code which showed how to page with a repeater. All very excited as I had been looking for this all...
0
by: manywolf | last post by:
I have an aspx page that fires the page load event twice for every load. I tried every fix that was suggested in all the posts on this and other forums. None changed the behavior. After one post that...
11
by: fiefie.niles | last post by:
I am using ASP.NET 2005 and I have a simple form. Page_Load calls a sub mySub that does not do anything (for testing purposes). But, Page_Load gets called twice. On every single ASPX page in my...
4
by: TarTar | last post by:
Hello, I have already posted this problem, but I have not received any response yet. I will try to describe it again. We have a list control (e.g. DataList) and an ObjectDataSource on an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.