How to show modal popup with yes and no button inside loop in asp.net

痞子三分冷 提交于 2019-12-11 17:30:17

问题


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.

来源:https://stackoverflow.com/questions/45213246/how-to-show-modal-popup-with-yes-and-no-button-inside-loop-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!