Re: Page_Load gets called twice

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Are you setting AutoEventWireup to true
(or are you not defining it, since by default it is true) ?

Page events are automatically bound to methods that use the naming convention of
Page_event, such as Page_Load, when you set AutoEventWireup to true or not set it to false.

If you set AutoEventWireup to true, and then use the Handles statement,
you will get Page events called twice, once by AutoEventWireup,
and again when you use Handles.

Test by setting AutoEventWireup to false, or by eliminating the Handles statement.



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/
===================================
<fiefie.niles@xxxxxxxxx> wrote in message
news:1177889150.489830.170860@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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 site, Page_Load gets called twice. Why
is that and how can I fix this problem ?
Thank you very much.

Imports System.IO
Namespace myProject
Partial Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents HyperLink1 As
System.Web.UI.WebControls.HyperLink

#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region

Protected Sub Page_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load, Me.Load
mySub()
End Sub
Sub mySub()
End Sub
End Class
End Namespace




.



Relevant Pages

  • Re: Formsauthentication - Page_Load problem
    ... private void InitializeComponent() ... That should work...not sure about the requirement for forms auth, ... I tent to always set my autoeventwireup to false anyway. ... >>You are basically adding an event hook to that sub. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Formsauthentication - Page_Load problem
    ... Why does AutoEventWireup have to be set to false for the ... TIA - John. ... >Public Sub Page_LoadHandles MyBase.Load ... >the load event of the class that your page is ...
    (microsoft.public.dotnet.framework.aspnet.security)