questa è la pagina che funziona benissimo. Fa il submit in un'altra pagina
codice:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="a.aspx.vb" Inherits="prove_a" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
</style>
<script type="text/javascript">
// <![CDATA[
function btPBU_Click()
{
alert("Attenzione, stai per lasciare la pagina");
}
// ]]>
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:button ID="btPBU" runat="server" Text="PostBackUrl" PostBackUrl="~/scrivi_parametri.aspx" OnclientClick="btPBU_Click();" OnClick="btPBU_Click" />
</div>
</form>
</body>
</html>
se elimino il PostBackUrl allora si verifica il postback e viene richiamato il codice:
codice:
Protected Sub btPBU_Click(sender As Object, e As System.EventArgs)
Throw New Exception("Errore provocato")
End Sub
PRIMA il messaggio javascript; poi il postback con intercettazione dell'errore 