Skip to content
Loading
+2
  • Naimish Makwana
    +2

    To handle the actions when the user presses the Delete or Cancel button in your modal popup on the Department.aspx WebForm, you can follow these steps:

    1. Handle the Delete Button Click Event:
      • In your code-behind file (Department.aspx.cs), create an event handler for the lnkRecordDelete_Click event. This is where you will write the logic to delete the record.
    C#
    protected void lnkRecordDelete_Click(object sender, EventArgs e)
    {
        // Your logic to delete the record
        // For example:
        int recordId = Convert.ToInt32(hiddenFieldRecordId.Value);
        DeleteRecord(recordId);
    
        // Optionally, you can close the modal and refresh the page or update the UI
        ScriptManager.RegisterStartupScript(this, this.GetType(), "closeModal", "$('#myModal').modal('hide');", true);
        Response.Redirect(Request.RawUrl); // Refresh the page
    }
    
    private void DeleteRecord(int recordId)
    {
        // Your logic to delete the record from the database
    }

     

    1. Handle the Cancel Button Click Event:

      • The Cancel button already has the data-dismiss="modal" attribute, which will close the modal when clicked. No additional server-side code is needed for this action.
    2. Optional: Use a Hidden Field to Pass Data:

      • If you need to pass the record ID or other data to the server when the Delete button is clicked, you can use a hidden field.

     

    C#

     

    • Set the value of this hidden field using JavaScript when the modal is shown.

     

    JavaScript
    $('#myModal').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget); // Button that triggered the modal
        var recordId = button.data('record-id'); // Extract info from data-* attributes
        $('#').val(recordId);
    });

     

    By following these steps, you can effectively handle the Delete and Cancel actions in your modal popup. 

    Thanks

    +2