tags:

views:

112

answers:

2

i am using jquery plugin and i got stuck in how to display the confirmation window from code behind and if the user choose "ok" than go ahead delete otherwise ignore.

jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {
    jAlert('Confirmed: ' + r, 'Confirmation Results');
});

anybody have done similar?

A: 

Why do you need to display this from the code behind? The user will initiate an action on the client, which is where this should be done.

If you're trying to put this on a delete button or something that's auto-generated:

$('.delButton').click(function(){
  jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {
      jAlert('Confirmed: ' + r, 'Confirmation Results');
  });
}

where .delButton is a class you could add to your delete buttons (or you can do whatever else you need to find which ones you attach this to). if you need you can also put the .live in there so jQuery will auto-hook up on new elements.

After the click, the inner jAlert can be removed and you can do your other logic inside.

Ryan Ternier
I understand the calling from client but how would u execute on server side? Do you have sample code?
Abu Hamzah
You can register a Startup Script (depending on the type of postback you're doing) which can call a JS Function which has the necessary scripts in it for what you need it to do.
Ryan Ternier
A: 

it did not work with JConfirm i decided to go with JS

//Aspx:

  <asp:LinkButton ID="LinkButton1" runat="server" Text="Click Me" 
      onclick="LinkButton1_Click" />

//JS

 <script type="text/javascript">

  function MyMethod()
  {
     if(confirm('Are you sure?'))
     {
        alert('Deleted');
        return true;
     }
     else
     {
       alert('Not Deleted');
       return false;
     }
  }

</script>

//Code Behind (C#)
 protected void Page_Load(object sender, EventArgs e)
    {
        LinkButton1.Attributes.Add("onclick", "return MyMethod();");
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {

    }
Abu Hamzah