Gajulapalle.rajesh
Gajulapalle.rajesh

Reputation: 59

How to get javascript confirm popup value in c#.net

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();
}

Upvotes: 0

Views: 7257

Answers (4)

panky sharma
panky sharma

Reputation: 2159

   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
   }

Upvotes: 0

Lee Bailey
Lee Bailey

Reputation: 3624

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>

Upvotes: 0

Karthik
Karthik

Reputation: 2399

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.

Upvotes: 5

kostas ch.
kostas ch.

Reputation: 2035

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;
}

Upvotes: 0

Related Questions