Noelle
Noelle

Reputation: 782

SSIS packages gets run when asp.net page is refreshed

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

Answers (1)

Devraj Gadhavi
Devraj Gadhavi

Reputation: 3611

Make two separate pages

  1. Which has the button, which when clicked calls your SPs and runs the SSIS package as a SQL Agent Job
  2. Which loads data

Then

  • Redirect to page 2 from your page 1 button click after the SQL Server Agent Job is finished.
  • Load required data in the page load event of page 2

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

Related Questions