I would say the best option is to split your code into mutliple code blocks
In
ImageBtnSave_Click
callMethodForCalculatingTheGrade();
If(condition)
callMethodForRegisteringTheConfirmDialog(GradeName);
In callMethodForRegisteringTheConfirmDialog(GradeName)
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "script", "showConfirm('" + GradeName + " ');", true);
add this in the JS file - showConfirm(Grade)
function showConfirm(Grade) {
if (confirm("You are about to overrite the existing pay grade, contine overriting?") == true) {
__doPostBack('<%= this.cmdOverriteGrade.ClientID %>', "true");
return false;
}
return false;
}
add this dummy control in the HTML source add this control
<asp:Button ID="cmdOverriteGrade" runat="server" Style="display: none;" OnClick="cmdOverriteGrade_Click" />
in source code handle the click event of our dummy button
protected void cmdOverriteGrade_Click(object sender, EventArgs e)
{
try
{
string confirmResult = (this.Request["__EVENTARGUMENT"] == null) ? string.Empty : this.Request["__EVENTARGUMENT"];
if (confirmResult == "true")
{
}
}
catch (Exception ex){
}
}
mark as solution if it answer your question