Link to home
Start Free TrialLog in
Avatar of brisbine
brisbine

asked on

Refresh & PostBack

I have a aspx form with some buttons.  When one of the buttons is clicked it executes a stored procedure that assigns some records to the associate logged in.  The problem is that when the page is refreshed by pressing F5 the page is resubmitted and the code is executed as if the button had been pressed again.

Is there a way to determine if the button has been clicked, or if the PostBack is occurring because the browser is refreshed?  Is there another way to handle this situation that I am unware of?

PS.  I am using the HtmlControls library and have tried adding actions in the InitializeComponent() section.

Thanks in advance for any suggestions.
Avatar of testn
testn

Why don't you handle it through OnServerClick handler?

<input type="button" runat="server" onserverclick="xxxxx">
Avatar of brisbine

ASKER

When I refresh (F5) the browser window the code gets executed again, the same as if I had clicked the button.  Any other suggestions?
can you post your code?
ASKER CERTIFIED SOLUTION
Avatar of krees
krees

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
krees is right try :

if (!IsPostBack)
{
 /// Good stuff here
}
how about

if(IsPostBack)
  return;

:)
you can try using session control maybe?

when the page is first run, set a sentinel flag as a session variable.

Then you can check for the existence of that flag when you start up the page. if it exists, don't run the code to do the updates. if it doesn't exist, set it, then run your code.
I haven't had time to test this yet, but I am going to give you the points for your helpful comments.

Thanks.