Detect source of the postback

Is there a way to detect if a postback was caused by a button click, vs someone hitting the browser refresh button?
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
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.

Paul MacDonaldDirector, Information SystemsCommented:
Yes, because a refresh <> a postback.
0
Paul MacDonaldDirector, Information SystemsCommented:
For the sake of clarity, you check for IsPostBack in the Page.Load and do (or not do) some action based on that:

 If Not IsPostBack Then
 ...
 End If
0

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:
Hmmmm....

I'll have to see how my other question is answered, because clicking the browser refresh button fires code "as if" I had clicked a button on my form.

In my mind, that does not reconcile with what you just stated.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Paul MacDonaldDirector, Information SystemsCommented:
I'm not suggesting code doesn't run when a page loads, I'm stating that a postback is not the same thing as a refresh.  

It's possible to write ASP.Net code to detect a postback.  If it's not a postback, then it must be a refresh.
0
disruptCommented:
Use Request.Form["__EVENTTARGET"] which stores the unique id of the control that caused the postback
0
Tom KnowltonWeb developerAuthor Commented:
>>>>Use Request.Form["__EVENTTARGET"] which stores the unique id of the control that caused the postback

==========================

This sounded like something interesting to do.

1)  When I first visit the page, Request.Form["__EVENTTARGET"] is null.

2)  When I click the button, Request.Form["__EVENTTARGET"] contains the ID of the button

3)  When I click the refresh button for the browser itself, Request.Form["__EVENTTARGET"] contains the ID of the button again.

It is the 3rd item that does not make sense to me.
0
Tom KnowltonWeb developerAuthor Commented:
As far as my code is concerned, there seems to be no distinction between a refresh and a postback.
0
Paul MacDonaldDirector, Information SystemsCommented:
Can you post your code?  Just a bit where you're trying to branch between postback and refresh...
0
Tom KnowltonWeb developerAuthor Commented:
thx
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.