当confirm返回false时,由于javascript中的click事件被取消,所以没有回发。如果您想在单击取消后进行回发,则需要稍微更改代码:
服务器端:
protected void Page_Load(object sender, System.EventArgs e)
{
btn_submit.Click += btn_submit_click;
btn_submit.OnClientClick = @"return getConfirmationValue();";
}
protected void btn_submit_click(object sender, ImageClickEventArgs e)
{
bool type = false;
if(hfWasConfirmed.Value == "true")
{
//If clicks OK button
}
else
{//If clicks CANCEL button
}
}
在客户端:
<asp:HiddenField runat="server" id="hfWasConfirmed" />
<asp:Panel runat="server">
<script>
function getConfirmationValue(){
if( confirm('Student has not completed all the steps? Are you sure you want to submit the details?')){
$('#<%=hfWasConfirmed.ClientID%>').val('true')
}
else{
$('#<%=hfWasConfirmed.ClientID%>').val('false')
}
return true;
}
</script>
</asp:Panel>