catchブロックでエラーを処理している場合、何ができるか-javascript変数を宣言し、その変数にエラーテキストを設定します。
var errorDescription = ""; //Will hold the error description (in .aspx page).
エラーが発生した場合は、catch
ブロックでこれを行います-
try
{
//Code with error
}
catch(Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "ErrorVariable", string.Format("errorDescription = '{0}'; CloseWindow();", ex.Message), true);
}
上記のコードの機能-エラーの説明を設定CloseWindow()
し、aspxページで関数を呼び出します。この関数には、次のコード行が含まれます-
function CloseWindow() {
window.parent.window.SetError(errorDescription);
self.close();
}
この関数は、親ウィンドウの関数を呼び出して、それ自体を閉じます。このSetError()
関数は、任意の方法でエラーを表示できます。