0

Hi I have been developing a page in asp.net web form. I have cancel button. When the cancel button is clicked I want to generate a Confirm Message box. Confirm Message box will appear based on some logic. If Yes is pressed from confirm box then button click will perform the rest of the work. And if NO is clicked then the rest of the work will not be done. I have written the following code both in server and client side. But it seems that confirm box is shown but if I click Yes the rest of the method function is not performed. Please let me know the problem.

JavaScript Code

function Confirm() {
            var confirm_value = document.createElement("INPUT");
            confirm_value.type = "hidden";
            confirm_value.name = "confirm_value";
            if (confirm("Are you sure you want to cancel the creation of this new person?")) {
                confirm_value.value = "Yes";
            }
            else {
                confirm_value.value = "No";
            }
            document.forms[0].appendChild(confirm_value);
        }

Server Side Code

if (IsFormDirty())
        {
            ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "alert", "Confirm();", true);
            string confirmValue = Request.Form["confirm_value"];

            if (confirmValue == "Yes")
            {
                if (!IsCprIxists())
                {
                    if (!string.IsNullOrEmpty(hidGuid.LM_DataValue))
                    {
                        if (DeleteNote(hidGuid.LM_DataValue))
                        {
                            Response.Redirect("~/920.aspx?UseSessionState=Y");
                        }
                    }
                    else
                    {
                        Response.Redirect("~/920.aspx?UseSessionState=Y");
                    }
                }
                else
                {
                    Response.Redirect("~/920.aspx?UseSessionState=Y");
                }
            }
        }
mnu-nasir
  • 1,642
  • 5
  • 30
  • 62
  • if you are using asp:Button here is [answer](http://stackoverflow.com/questions/14058116/confirm-postback-onclientclick-button-asp-net) – makison Feb 10 '16 at 12:49
  • sorry misunderstood question ))), you nee to submit form - document.forms[0].submit(); – makison Feb 10 '16 at 12:56

0 Answers0