Page_Load called twice???

Discussion in 'ASP .Net' started by Andy, Oct 17, 2003.

  1. Andy

    Andy Guest

    Visual Studio 2003 web form problem using C#.

    My Page_Load or OnInit routines seems to be called twice
    for every post back to the server.

    I have 2 web forms that produce this behaviour, all of
    the others just run these routines once.

    Any ideas!
     
    Andy, Oct 17, 2003
    #1
    1. Advertising

  2. Is it Page_Load, OnInit, or both? If it's just Page_Load, check if those
    two forms have AutoEventWireup="true" in addition to VS.NET's
    InitializeComponents() code to attach Page_Load to the OnLoad event.

    "Andy" <> wrote in message
    news:2d8ef01c394c3$48eb2750$...
    > Visual Studio 2003 web form problem using C#.
    >
    > My Page_Load or OnInit routines seems to be called twice
    > for every post back to the server.
    >
    > I have 2 web forms that produce this behaviour, all of
    > the others just run these routines once.
    >
    > Any ideas!
    >
     
    Bret Mulvey [MS], Oct 18, 2003
    #2
    1. Advertising

  3. Hi Andy,

    IN addition to what Bret said - is this page subclassed from another? In
    that case you may have the page constructor for both pages firing which
    means Page_Load() gets called twice...


    +++ Rick ---

    --

    Rick Strahl
    West Wind Technologies
    http://www.west-wind.com/
    http://www.west-wind.com/wwHelp
    ----------------------------------
    Making waves on the Web


    "Andy" <> wrote in message
    news:2d8ef01c394c3$48eb2750$...
    > Visual Studio 2003 web form problem using C#.
    >
    > My Page_Load or OnInit routines seems to be called twice
    > for every post back to the server.
    >
    > I have 2 web forms that produce this behaviour, all of
    > the others just run these routines once.
    >
    > Any ideas!
    >
     
    Rick Strahl [MVP], Oct 18, 2003
    #3
  4. Check out this faq, this might help you.
    http://www.extremeexperts.com/Net/FAQ/PageLoadFiringTwice.aspx

    --
    Saravana
    Microsoft MVP - ASP.NET
    www.extremeexperts.com



    "Andy" <> wrote in message
    news:2d8ef01c394c3$48eb2750$...
    > Visual Studio 2003 web form problem using C#.
    >
    > My Page_Load or OnInit routines seems to be called twice
    > for every post back to the server.
    >
    > I have 2 web forms that produce this behaviour, all of
    > the others just run these routines once.
    >
    > Any ideas!
    >
     
    Saravana [MVP], Oct 18, 2003
    #4
  5. Andy

    Andy Guest

    I think it's the Oninit thats being called twice, the
    sequence of events is as follows

    This bit of code is fired first-

    override protected void OnInit(EventArgs e)
    {
    InitializeComponent();
    base.OnInit(e);
    }

    then the Page_Load is fired
    then back to OnInit
    then back to Page_Load

    All pages have AutoEventWireup set to false.

    Cheers Andy

    >-----Original Message-----
    >Visual Studio 2003 web form problem using C#.
    >
    >My Page_Load or OnInit routines seems to be called twice
    >for every post back to the server.
    >
    >I have 2 web forms that produce this behaviour, all of
    >the others just run these routines once.
    >
    >Any ideas!
    >
    >.
    >
     
    Andy, Oct 20, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bminder
    Replies:
    1
    Views:
    2,196
    nfedin
    Feb 23, 2004
  2. z. f.
    Replies:
    0
    Views:
    580
    z. f.
    Oct 19, 2004
  3. Dot net work
    Replies:
    6
    Views:
    5,340
    Dot net work
    Nov 24, 2004
  4. Imran Aziz

    Page_load called twice on button click

    Imran Aziz, Sep 3, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    6,600
  5. Replies:
    12
    Views:
    1,008
    prasanth k
    Oct 5, 2009
Loading...

Share This Page