Forum guidelines
AuthorQuestion
how can i add confirm box in asp.net
Posted on: 15 Apr 2011
hello guys 

i am creating a project in asp.net 
and is that project i need to delete record with confirm box 
for example, if i press the delete button then confirm box show me this msg like "Are  you sure you want to delete" if i press OK then delete that record and if i press Cencel then record will not delete ....

so plz help me and guide me  and provide me the source code about perticuler task if u can ...

Thanks.

AuthorReply
Re: how can i add confirm box in asp.net
Posted on: 15 Apr 2011  
Write this javascript code on your asp.net button,s source code
onclientclick="return confirm('Are you sure want to delete current record')"
for example if you are using link button for delete then write
<asp:LinkButton ID="lnkDelete" CssClass="delete" Text="Delete"  runat="server" CommandName="del" CommandArgument='<%# Eval("ImageId") %>' onclientclick="return confirm('Are you sure want to delete current record')" />

If this information is helpful for you then mark as accepted answer.
Ankit Nandekar

Life is 10% of what happens to me and 90% of how I react to it.

Re: how can i add confirm box in asp.net
Posted on: 15 Apr 2011  
Hi faisal,
You can also use below code in ur code behind:

string strConfirmation="Are you sure you want to delete?";
btnRemove.Attributes.Add("onclick", "javascript:if(confirm('"+strConfirmation+"')== false) return false;");

Hope this code will solve your problem. :)         

Ravishankar Singh visit:http://sharepointwithravi.blogspot.com/
Re: how can i add confirm box in asp.net
Posted on: 15 Apr 2011  
hi Ravi bhai 

your code is working and benefital for me :)

by the way where were you? issay pehley wala question bhi ap sey poocha tha main ney...

actually your examples i can understand easily.. so can you please give me your personal ID that i able to contact u there and get solutions about my problems ...

thanks ... 

Re: how can i add confirm box in asp.net
Posted on: 15 Apr 2011  
Hi Faisal, Thank you so much for the complement. :) You can follow me through my blog or c-sharepcorner user group as a friend.You will get my id as well.
Ravishankar Singh visit:http://sharepointwithravi.blogspot.com/
Re: how can i add confirm box in asp.net
Posted on: 15 Apr 2011  
ok Ravi bhai..

i will get you..

but here is one problem with me 
actually i want to do this like that 

        string strConfirmation = "Are you sure you want to Delete";
        if ((btnDelete.Attributes.Add("onclick", "javascript:confirm('" + strConfirmation + "')")) == false)
        {
            Response.Write("value false");
        }
        else
        {
            Response.Write("True");
        }

but the Error : Operator '==' cannot be applied to operands of type 'void' and 'bool'

so how can i come over for it ...?

Thanks.


Re: how can i add confirm box in asp.net
Posted on: 15 Apr 2011  

 Instead of writing Confirmation message on code-behind, create a javascript function and bound it to Button's event.

 Because in future if you want to change the 
Confirmation message, you need to change in code-behind resulting in
 
 uploading of dlls again.

 
<script language="javascript" type="text/javascript">
        function DeleteMe() {
            if (confirm('Are you sure, you want to delete the record !') == false) { return false; }
            return true;
        }
  </script>

 On Page Load

 btn1.Attributes.Add("onclick", "javascript:if(DeleteMe()==false) {return false;};");


Mark as Answer, on the posts reply's that helped you !!!.
Re: how can i add confirm box in asp.net
Posted on: 15 Apr 2011  
try this code
onclientclick="return confirm('Are you sure want to delete current record')"
tell me this code is working or not

If this information is helpful for you then mark as accepted answer.
Ankit Nandekar

Life is 10% of what happens to me and 90% of how I react to it.

Re: how can i add confirm box in asp.net
Posted on: 15 Apr 2011  
Faisal, why you need this kind of logic, what are you trying to do?
Mark as Answer, on the posts reply's that helped you !!!.
Re: how can i add confirm box in asp.net
Posted on: 15 Apr 2011  
Try this
<html>
<head>
<script type="text/javascript">
function show_confirm()
{
var r=confirm("Press a button");
if (r==true)
  {
  alert("You pressed OK!");
  }
else
  {
  alert("You pressed Cancel!");
  }
}
</script>
</head>
<body>

<input type="button" onclick="show_confirm()" value="Show confirm box" />

</body>
</html>

Regards
 Mayur
Re: how can i add confirm box in asp.net
Posted on: 15 Apr 2011  


Hello Faisal



       If you want to show only extender then lots of other guys had provide solution aabove to my ans.

My ans is:-
you can also use ajax confirmbutton extender to show confirm box. following is the link. for your refrence.

"http://www.mindstick.com/Articles/4e57a4f3-65aa-47a4-89e2-fed3ef6d5f8b/?Ajax%20Toolkit%20ConfirmButtonExtender%20Control%20in%20ASP%20Net"


       here is the another way to show confirm box extender +modelpopup extender. to show attractive confirmbox extender.

"http://www.codeproject.com/KB/ajax/ASPModalInAction.aspx?msg=3291332&PageFlow=Fluid"

Thanks And Regards
Omkar.
Re: how can i add confirm box in asp.net
Posted on: 18 Apr 2011  
thread resolved?
Mark as Answer, on the posts reply's that helped you !!!.

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.