ダウンロード時に二回目以降のクリックイベントが動作しない場合の回避方法

念のためメモ。以下のURLを参考にして実装すると回避できます。
After file added to response, post back stops working in WebPart


1.以下のコードをPageクラスに追加(拡張メソッドでもよし)

protected void AlterFormSubmitEvent()
{
    StringBuilder script = new StringBuilder();
    script.AppndLine("var exportRequested = false;");
    script.AppndLine("var beforeFormSubmitFunction = theForm.onsubmit;");
    script.AppndLine("theForm.onsubmit = function(){");
    script.AppndLine("var returnVal = beforeFormSubmitFunction();");
    script.AppndLine("if(exportRequested && returnVal){_spFormOnSubmitCalled=false; exportRequested=false;}");
    script.AppndLine("return returnVal;");
    script.AppndLine("};");
    script.AppndLine(this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alterFormSubmitEvent", script.ToString(), true));
}

2.ダウンロードするボタンのOnClientClickで「exportRequested=true;」を設定


これで二回目とか関係なく正常にクリックイベントが動作します。
これはSharepointはもともと二重送信防止の制御が入っているのが原因と思われます。
リクエスト時にフラグを立てるのでダウンロードなどリクエストをフラッシュしてしまうと
フラグが立てぱなしになってしまうからではないかと推測しています。