Page-load twice

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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
 
Thats interesting, Ive never come across this before , why is that Hans ?

Regards Mr N
 
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.




Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
 
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.
 
Thanks for that explaination, I have never seen this set to true, so its an
eye opener for me.

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

Regards Mr N
 
Back
Top