• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 452
  • Last Modified:

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.
0
brisbine
Asked:
brisbine
1 Solution
 
testnCommented:
Why don't you handle it through OnServerClick handler?

<input type="button" runat="server" onserverclick="xxxxx">
0
 
brisbineAuthor Commented:
When I refresh (F5) the browser window the code gets executed again, the same as if I had clicked the button.  Any other suggestions?
0
 
SegFaultCommented:
can you post your code?
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!

 
kreesCommented:

try this:

is (!IsPostBack)

{
    // run your code here

}

0
 
dhodgeCommented:
krees is right try :

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

if(IsPostBack)
  return;

:)
0
 
SegFaultCommented:
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.
0
 
brisbineAuthor Commented:
I haven't had time to test this yet, but I am going to give you the points for your helpful comments.

Thanks.
0

Featured Post

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!

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