client side and then server side delete

I have the following code:

<asp:Button ID="btnDelete" runat="server" Text="Delete Report"   OnClientClick="return confirm ('This will delete the report.  Continue?');" />

Once the user clicks on OK how do I get the server side script to fire that actually deletes.

I had

OnClick="btnDelete_Click"

on the above code but nothing
happened.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Open your code behind and add

public void btnDelete_Click(object sender, EventArgs e)
{
    //Your logic here
}

Method 2

You can use bootstrap’s modal.

<asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="showDialog_Event" />

Page:

<div class="container">
    <div id="modalDialog" class="modal" role="dialog">
       <div class="modal-dialog modal-sm" data-backdrop="static">
           <div class="modal-content">
                <div class="modal-header">
                     <div class="modal-title text-center">
                           <h4>Message</h4>
                      </div>
                </div>
                <div id="modalBodyDialog" class="modal-body">
                </div>
                <div class="modal-footer">
                  <asp:Button runat="server" ID="btnOkDialog" CssClass="btn btn-default" Text="Ok" OnClick="btnOkDialog_Click" />
                  <input type="button" value="Cancel" data-dismiss="modal" />
                 </div>
            </div>
       </div>
   </div>

Code:

public void showDialog_Event(object sender, EventArgs e) {
  System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append(@"<script type='text/javascript'>");
        sb.Append("$('#modalDialog').modal({'backdrop': 'static', 'keyboard': 'static', 'show': true});");
        sb.Append("$('#modalBodyDialog').html('<ul><li>");
        sb.Append(message);
        sb.Append("</li></ul>')");
        sb.Append(@"</script>");
        Page.ClientScript.RegisterStartupScript(this.GetType(), "ModalScript", sb.ToString(), false);
}

Get event confirm (btn OK)

public void btnOkDialog(object sender, EventArgs e) {
// your code for delete
}

This example need bootstrap and jquery.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x