简体   繁体   中英

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.

Open your code behind and add

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM