Why Do IsPostBack and Master.IsPostBack Always Fire Twice?

Discussion in 'ASP .Net' started by Joey, Dec 30, 2005.

  1. Joey

    Joey Guest

    I am currently working on a (file-system) website in C# in VS2005. I am
    programming counters for the different webpages. I wrote a class and
    enum with functionalities exposed like...

    Counter.Hit(PageCounter.Home)

    ....and then I put it in the Page_Load section and within the
    if(!Page.IsPostBack) block on my web form.

    I can see that during debugging that the !Page.IsPostBack block fires
    and tests true (the code within is executed) TWICE each time the page
    is viewed.

    This is really weird. Why does it do it twice each time? This page is
    webform that is linked to a master page, if that makes any difference.

    I also tried !Page.Master.IsPostBack, but I got the same behavior.

    Does anyone have any ideas on this? I can't afford to have my counter
    hit twice each (one) time a page is accessed!

    Thanks.
    Joey, Dec 30, 2005
    #1
    1. Advertising

  2. One would get the page events to fire up twice (as in your described
    scenario) if I set the AutoEventWireUp=true and add page event handlers in
    the OnInit method :
    http://www.webswapp.com/CodeSamples/aspnet20/AutoEventWireUp_True_Error.aspx

    The solution would be either of these approaches:
    http://www.webswapp.com/CodeSamples/aspnet20/AutoEventWireUp_False.aspx
    http://www.webswapp.com/CodeSamples/aspnet20/AutoEventWireUp_True.aspx
    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Joey" wrote:

    > I am currently working on a (file-system) website in C# in VS2005. I am
    > programming counters for the different webpages. I wrote a class and
    > enum with functionalities exposed like...
    >
    > Counter.Hit(PageCounter.Home)
    >
    > ....and then I put it in the Page_Load section and within the
    > if(!Page.IsPostBack) block on my web form.
    >
    > I can see that during debugging that the !Page.IsPostBack block fires
    > and tests true (the code within is executed) TWICE each time the page
    > is viewed.
    >
    > This is really weird. Why does it do it twice each time? This page is
    > webform that is linked to a master page, if that makes any difference.
    >
    > I also tried !Page.Master.IsPostBack, but I got the same behavior.
    >
    > Does anyone have any ideas on this? I can't afford to have my counter
    > hit twice each (one) time a page is accessed!
    >
    > Thanks.
    >
    >
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Dec 30, 2005
    #2
    1. Advertising

  3. Joey

    Joined:
    Oct 9, 2008
    Messages:
    2
    Review your aspx page to see whether any image control which has its src or imageUrl is empty. Give some static url to that attribute.
    , Oct 9, 2008
    #3
    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. =?Utf-8?B?QW5kcmV3?=

    Why it is always: this.IsPostBack = false?

    =?Utf-8?B?QW5kcmV3?=, Feb 3, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    9,092
    =?Utf-8?B?QW5kcmV3?=
    Feb 3, 2006
  2. Doug McCann
    Replies:
    1
    Views:
    1,007
    William Brogden
    Aug 5, 2004
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,850
    Smokey Grindel
    Dec 2, 2006
  4. Kenneth Baltrinic
    Replies:
    1
    Views:
    504
    bruce barker
    May 31, 2007
  5. Joey
    Replies:
    2
    Views:
    468
Loading...

Share This Page