473,387 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Why Do IsPostBack and Master.IsPostBack Always Fire Twice?

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.

Dec 30 '05 #1
1 1934
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/...rue_Error.aspx

The solution would be either of these approaches:
http://www.webswapp.com/CodeSamples/...eUp_False.aspx
http://www.webswapp.com/CodeSamples/...reUp_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.

Dec 30 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tim | last post by:
To make !Page.IsPostBack to work, do I need to set any properties at page level or in the config files(Web, machine) or aspx files. Because code in under the !IsPostBack is executing twice and...
2
by: patrick_a | last post by:
Hi, I'm having trouble with using !IsPostBack. I want to create a linkbutton within a table when the page loads the first time and then have the page redirect based on the...
1
by: Alan Samet | last post by:
I know what's causing this, but how do I work around it? ********************** file: test.master: ********************** <%@ Master %> <script runat=server> void Page_Load(object sender,...
4
by: lakepeir | last post by:
Hello, I have combobox with a selectedindexchanged method that seems to be called when starting the application, launching the form with the combobox and making a change in the drop down box of...
1
by: Kenneth Baltrinic | last post by:
I am having a very odd problem. On a page that was working until very recently we are now encountering the following situation: The page is a very basic fill in the blank form used for changing...
1
by: Kenneth Baltrinic | last post by:
I am having a very odd problem. On a page that was working until very recently we are now encountering the following situation: The page is a very basic fill in the blank form used for changing...
6
by: anthonykallay | last post by:
Hi there, I dont this this a bug but i cant get my head around it.. I have a master page that has a login control on it, to log in i press the button and the page posts back, however on the page...
2
by: Joey | last post by:
This is causing us a lot of pain right now. Does anyone know why this happens and, more importantly, how to fix it? TIA JP
3
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
why will event's like on page load not fire in a master page that has been inherited? -- (i''ll be asking a lot of these, but I find C# totally way cooler than vb and there''s no go''n back!!!)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.