Page_Load getting called multiple times

For reasons I am not yet sure of, in my Default.aspx page, the Page_Load event is getting called multiple times.

I have one particular piece of code, a User Control, that does not deal well with being called multiple times like that.


Is there a way I can temporarily rig the code so that even if Page_Load gets called say, 100 times, that the call to my User Control will only get called once?

That is the main priority.  So I can stabilize the web page somewhat (I am 2 days late delivering it).

Second is...hunting down the cause.
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pratima PharandeCommented:
Have you check Ispostback condtion in PageLoad ?

add the code if Ispostback is fasle then your code will called only once when page loaded
Roman GhermanSenior Software EngineerCommented:
do you have any form.submit() on the page?

or do you do any ajax calls when page is loading?

there can be a lot of problem sources, you will need to post the code, without it we will keep guessing.
Tom KnowltonWeb developerAuthor Commented:
That's the bizzarre thing...each of the 4 times (actually it's only 2 times right now) IsPostBack is false EACH TIME.  So the code gets entered two times  (I may have that logic backwards....I'm very tired)
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Roman GhermanSenior Software EngineerCommented:
if IsPostBack is false each time that means that you have a page reload or page redirect somewhere in the code, severside or client side, doesn't matter
Pratima PharandeCommented:
you can try one thing
Use Session , set the session variable when first time you load the page

and later on check the session variable if its set then do not excute the code again

hope it helps you
Tom KnowltonWeb developerAuthor Commented:
I tried that trick, also, at some point.

But if the page is getting called externally....even that does not work because each request for the page gets it's own session vars, right?
Pratima PharandeCommented:
Yes,

then you can store it in Database with some parameters like date and user etc
and check in the database

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tom KnowltonWeb developerAuthor Commented:
I will try that at my next opportunity.

Going home, going to bed.  I am 5 hours shy of being up 24 hours straight.
Tom KnowltonWeb developerAuthor Commented:
thx
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.