0

I want to get javascript confirm popup returns value from code behind. Here when user select ok button on confirm popup some code goes here, or user select cancel button on the popup some code goes here.

How to get the selected value from code behind?

My code is;

if (ClientScript.RegisterStartupScript(typeof(Page), "Confirm", "<script type='text/javascript'>return Confirm('Do you Want to Delete');</script>"))
{
    db.Deletedevicedate();
    clear();
}
else
{
    clear();
}

4 Answers 4

5

On your client click event try this

OnClientClick = " return confirm('Do you want to proceed ?');"

Example:

   <asp:Button runat="server" OnClientClick = " return confirm('Do you want to proceed ?');" />

if they click ok only then the button click event is called or else a page postback wont happen.Write your code to delete data in the button click.

Sign up to request clarification or add additional context in comments.

4 Comments

And how to get the confirm result in order to delete or not?
@kostasch. the page wont postback when cancel is clicked and hence no event is executed.When ok is clicked the button click event happens
I wrote the comment in order to explain your answer :)
@kostasch. thanks for that only after your comment i added the explanation to the answer
0

Try to use ajax.

javascript section

 var result = confirm("Do you Want to Delete?");
if (result) 
{
    //do ajax call and delete from database
    return true;
} 
else 
{
    return false;
}

Comments

0

In order to get this working with minimal changes to your code, I would add a hidden field to your page (that you can get the value of in your code-behind) and set the value of this field using JavaScript:

<script type='text/javascript'>$('#yourhiddenfield').val(Confirm('Do you Want to Delete'));</script>

Comments

0
   if
   {
       ImageButton BtnDelete = (ImageButton)e.Row.FindControl("btnDelete");
       BtnDelete.Attributes.Add("onclick", "javascript:return confirm('Delete this payment method?');");
   }
   else
   {
       // No Alert here or additional functionality
   }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.