0

In gridview if user click delete button i want to delete that record so after clicking delete button i want to show confirmation box not alert box and from confirmation box i want to check if user click yes then delete the record else cancel I want how to check if user click yes or no from confirm box

HyperLink hypComplaintMasterDelete =HyperLink)e.Row.FindControl("hypComplaintMasterDelete");
hypComplaintMasterDelete.NavigateUrl = string.Format("{0}?control=CommitteeMembersDetails&Mode=De&id={1}", MasterDataHelper.NAVIGATE_Committee, lblCollagecommitteeUsersID.Text);
hypComplaintMasterDelete.Attributes.Add("onclick", "return confirm('Are you sure \n You want to delete);");
Sumeet
  • 111
  • 1
  • 16
  • 1
    possible duplicate of [how to show message box in asp.net](http://stackoverflow.com/questions/7836197/how-to-show-message-box-in-asp-net) – Sayse Jul 21 '14 at 06:38
  • don't want alert box want confirmation box and according to selection perform action – Sumeet Jul 21 '14 at 06:43
  • See Ali Sarshogh's answer, if that isn't what you wanted, please update your question to include your research effort. that was about the second link in a search for "messagebox asp.net" – Sayse Jul 21 '14 at 06:43
  • Let me tell what i want to do In gridview if user click delete button i want to delete that record so after clicking delete button i want to show confirmation box not alert box and from confirmation box i want to check if user click yes then delete the record else cancel I want how to check if user click yes or no from confirm box – Sumeet Jul 21 '14 at 06:51
  • See Ali Sarshogh's answer – Sayse Jul 21 '14 at 06:54

1 Answers1

1

In GridView place an ImageButton and pass the Record ID in CommandArgument. On OnClientClick call a JS function with confirm. If it will return true OnClick event will fire else nothing will happen.

ASPX

<asp:ImageButton ID="imgDelete" runat="server" CommandArgument='<%# Eval("ID") %>'     
AlternateText="Delete" ImageUrl="YourImagePath" OnClick="imgDelete_Click" 
OnClientClick="return checkDelete()" />

JS

<script type="text/javascript">
    function checkDelete() {
        if (confirm('Are you sure you want to delete ?')) {
            return true;
        }
        else {
            return false;
        }
    }
</script>
Lukasz Koziara
  • 4,274
  • 5
  • 32
  • 43
Afnan Ahmad
  • 2,492
  • 4
  • 24
  • 44