I have an app where I use Confirm Message Box pop up. The application checks if a report (crystal) alredy exists as a .pdf, if so I show a confirm pop up and if click is OK the I plan to replace existing .pdf (ie save to a folder)
I have following code snippet. The issue is when confirm pop up is displayed, I have to click the OK twice before it enters into the "btnConfirm" sub
Step 1 - Check report exists
Code:
Response = CheckDocumentExists(FilePath, DocumentName)
If Response(1) = "Yes" Then
MsgBox_Confirm(Response(0))
Step 2 - Report exists, call confirm pop up
Code:
Public Overloads Sub ASPNET_MsgBox_Confirm(ByVal Message As String) 'Confirm
Page.ClientScript.RegisterStartupScript(Me.GetType(), "Confirmation", "Confirmation();", True)
End Sub
Step 3 - Handle Response to pop up
Code:
<scripttype="text/javascript"language="javascript">
function Confirmation()
{
if(confirm("Daily Sales Report already exists. Do you want to replace it ?")== true)
{
//Calling the server side code after confirmation from the user
document.getElementById('<%=btnConfirm.ClientID%>').click();
}
}
</script>
<asp:ButtonID="btnConfirm"OnClientClick="return Confirmation();"runat="server"style="display: none"Text="Confirm"OnClick="btnConfirm_Click"/>
Step 4 - Action when OK clicked
Code:
Protected Sub btnConfirm_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim Response As String
Response = "Debug, I reached this point ..."
End Sub