Reputation: 782
I have an asp.net web page with a button that when clicked it calls 2 stored procedures, then runs an SSIS package as a SQL Agent Job and finally reloads the data on the page. This all runs fine.
My problem is if the page is then refreshed using the browser refresh button it executes the button click event again.
How can I stop this from happening?
Thanks Noelle
Upvotes: 1
Views: 177
Reputation: 3611
Make two separate pages
Then
Have a property wrapped on ViewState
in page 1 like this.
protected Boolean IsRequestAlreadyProcessed
{
get
{
return Convert.ToBoolean(this.ViewState["IsRequestAlreadyProcessed"]);
}
set
{
this.ViewState["IsRequestAlreadyProcessed"] = value;
}
}
Now check this property in your page 1 button click event like this.
protected void yourButton_Click(Object sender, EventArgs e)
{
if (!this.IsRequestAlreadyProcessed)
{
this.IsRequestAlreadyProcessed = true;
//Carry out all your SQL Agent Job operations here...
Response.Redirect("~/ToYourPage2.aspx");
}
}
Upvotes: 1