Page-load twice

G

Guest

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 several hours on this

NB even i removed all events called on page load but still same problem

Regards
 
M

Mr Newbie

As far as I know the only thing which would cause the page to reload is a
either some Javascript in the OnLoad event for the page which is doing
something, or a META-EQUIV tag which forces the browser to reload.

HTH
 
H

Hans Kesting

MaryA said:
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 several hours on this

NB even i removed all events called on page load but still same
problem

Regards

What language are you using?

do you have AutoEventWireup="false" in the @Page directive?
(this set to true is usually the reason Page_Load is called twice)

Hans Kesting
 
M

Mr Newbie

Thats interesting, Ive never come across this before , why is that Hans ?

Regards Mr N
 
J

Juan T. Llibre

Pages support an automatic way to bind their events to methods.

If the AutoEventWireup attribute of the @ Page directive is set to true
(or if it is missing, because by default it is true), page events are automatically
bound to methods that use the naming convention of Page_event,
such as Page_Load and Page_Init.

The AutoEventWireup attribute requires that the
page event handlers have specific, predictable names.

If you want to create your own names for page event handlers, you can set
AutoEventWireup to false and then bind the events to the methods explicitly.

For example, in Visual Basic, you can use the Handles keyword to perform the binding.

If you include explicit binding, you must make sure that the
AutoEventWireup is disabled so that the method is not called twice,
once automatically by AutoEventWireup and another time by
your explicit binding.
 
H

Hans Kesting

Mr said:
Thats interesting, Ive never come across this before , why is that
Hans ?
Regards Mr N

AutoEventWireup=true (default!) will automatically hook Page_Load to the
Load event of the Page. When you also add it "by hand" (could be
done automatically for a C# codebehind) with a this.Load += ...,
then it is added a second time (and executed a second time).

from MSDN:
----
Alternatively, the ASP.NET page framework also supports an automatic way to associate page events and methods. If the
AutoEventWireup attribute of the Page directive is set to true (or if it is missing, since by default it is true), the page
framework calls page events automatically, specifically the Page_Init and Page_Load methods. In that case, no explicit Handles
clause or delegate is needed.

The disadvantage of the AutoEventWireup attribute is that it requires that the page event handlers have specific, predictable names.
This limits your flexibility in how you name your event handlers. Therefore, in Visual Studio, the AutoEventWireup attribute is set
to false by default and the designer generates explicit code to bind page events to methods.

If you do set AutoEventWireup to true, Visual Studio will generate code to bind the events and the page framework will automatically
call events based on their names. This can result in the same event code being called twice when the page runs. As a consequence,
you should always leave AutoEventWireup set to false when working in Visual Studio.
 
M

Mr Newbie

Thanks for that explaination, I have never seen this set to true, so its an
eye opener for me.

Regards Mr N
 
M

Mr Newbie

Thanks for that explaination, I have never seen this set to true, so its an
eye opener for me.

Regards Mr N
 
Joined
Apr 24, 2009
Messages
1
Reaction score
0
Look for a double entry after "Handles" such as this:

"Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load"

If the second event exists, remove it. Here I woud remove ", Me.Load" since it is the same event under a different alias.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top