How to show modal popup with yes and no button ins

2019-09-16 23:48发布

There's a generate button on my page which generate files depending on the count given by user(like if 10 is the input then 10 files will be generated) and in that loop i want to ask user for there confirmation if they press the generate button again and i will show this popup for each file getting generated(like 10 times popup should come up if they press the button again) so based on the yes or no button in modal popup i will generate the file.

This is the code on my button:

protected void Button1_Click(object sender, EventArgs e)
{
    int c = 0;
    for (int i = 0; i < 10; i++)
    {
        if (//some condition)
        {
            c++;
            ScriptManager.RegisterStartupScript(this, this.GetType(), "getConfirmation", "getConfirmation(this, 'Please confirm','Are you sure you want to Generate Again?');", true);
        }
    }
    if (c > 0)
    {
        string message = c + " Folders are generated successfully";
        string header = "Info";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "LaunchServerSide", "openModal('" + message + "','" + header + "','TranChargesMonthlyProcessing.aspx');", true);
    }
    else
    {
        string message = c + " Folder generated";
        string header = "Info";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "LaunchServerSide", "openModal('" + message + "','" + header + "','TranChargesMonthlyProcessing.aspx');", true);
    }
}

protected void btnYes_Click(object sender, EventArgs e)
{

}

//on cancel click of modal pop
protected void btnNo_Click(object sender, EventArgs e)
{

}

This is the Modal PopUp:

<div id="modalPopUp" class="modal fade" role="dialog">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">
                    <span id="spnTitle"></span>
                </h4>
            </div>
            <div class="modal-body">
                <p>
                    <span id="spnMsg"></span>.
                </p>
            </div>
            <div class="modal-footer">
                <asp:Button runat="server" ID="btnYes" type="button" class="btn btn-default" data-dismiss="modal" Text="Yes"></asp:Button>
                <asp:Button runat="server" ID="btnNo" type="button" class="btn btn-default" data-dismiss="modal" Text="No"></asp:Button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
  function getConfirmation(sender, title, message) {
    console.log("asas");
    $("#spnTitle").text(title);
    $("#spnMsg").text(message);
    $('#modalPopUp').modal('show');
    $('#btnConfirm').attr('onclick', "$('#modalPopUp').modal('hide');setTimeout(function(){" + $(sender).prop('href') + "}, 50);");
    return false;
  }
</script>

Any help will be appreciated.

0条回答
登录 后发表回答