Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 430
  • Last Modified:

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?
0
Tom Knowlton
Asked:
Tom Knowlton
  • 4
  • 4
2 Solutions
 
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
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now