调用customercript

时间:2017-07-13 10:31:45

标签: c# jquery asp.net modal-dialog

我正在显示带有确认和取消按钮的模态弹出窗口,当在gridview内单击按钮时调用该按钮。但是当单击onclick函数时,我在某些条件下调用scriptmanager,如果条件失败,那么我想停止进一步执行。

这是我的网络形式:

<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">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="button" id="btnConfirm" class="btn btn-primary">
                            Yes, please</button>
                    </div>
                </div>
            </div>
        </div>
<asp:GridView ID="GrdChargeCodeProcessing" runat="server"
    AutoGenerateColumns="False"
    AllowSorting="true" AllowPaging="true" PageSize="7"
    CssClass="table table-responsive table-bordered table-hover AspGridview">
    <PagerStyle CssClass="pagination" />
    <Columns>
        <asp:TemplateField HeaderText="Select Code">
            <HeaderTemplate>
                <asp:CheckBox ID="SelectAllCode" runat="server" OnCheckedChanged="SelectAllCode_CheckedChanged" AutoPostBack="true" />
            </HeaderTemplate>
            <ItemTemplate>
                <asp:CheckBox ID="SelectCode" runat="server" OnCheckedChanged="SelectCode_CheckedChanged" AutoPostBack="true" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="TOTAL_MEMBERS" SortExpression="TOTAL_MEMBERS" HeaderText="Total Members"></asp:BoundField>
        <asp:BoundField DataField="TOTAL_ANNEXURES" SortExpression="TOTAL_ANNEXURES" HeaderText="Total Annexures"></asp:BoundField>
        <asp:BoundField DataField="PROCESSED_BY" SortExpression="PROCESSED_BY" HeaderText="Processed By"></asp:BoundField>
        <asp:BoundField DataField="PROCESSED_DATE" SortExpression="PROCESSED_DATE" HeaderText="Processed Date"></asp:BoundField>
        <asp:TemplateField HeaderText="Actions">
            <ItemTemplate>
                <asp:Button ID="LnkViewButton" runat="server" Text="View" UseSubmitBehavior="false" OnClick="LnkViewButton_Click" CssClass="AspButton btn btn-primary"></asp:Button>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Actions" HeaderStyle-Width="120px">
            <HeaderTemplate>
                <asp:LinkButton ID="LnkGenerateAllButton" BackColor="#ffffff" ForeColor="#000000" runat="server" OnClientClick="return getConfirmation(this, 'Please confirm','Are you sure you want to Generate Again?');"
                    OnClick="LnkGenerateAllButton_Click" CssClass="AspButton btn btn-primary"></asp:LinkButton>
            </HeaderTemplate>
            <ItemTemplate>
                <asp:LinkButton ID="LnkGenerateButton" runat="server" Font-Underline="true"
                    OnClick="LnkGenerateButton_Click" CssClass="AspButton btn btn-primary">Generate</asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <HeaderStyle BackColor="#0089d0" ForeColor="White" HorizontalAlign="Left" />
    <PagerStyle BackColor="#0089d0" Font-Bold="true" ForeColor="White" />
    <EmptyDataTemplate>No Record Found</EmptyDataTemplate>
    <EditRowStyle BackColor="#c0e6fa" />
</asp:GridView>

<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>

这是后端:

protected void LnkGenerateButton_Click(object sender, EventArgs e)
{
    GridViewRow row = ((LinkButton)sender).NamingContainer as GridViewRow;
    string ChargeCode = row.Cells[1].Text;
    string path = "";
    CheckBox chktmp = (CheckBox)row.FindControl("SelectCode");
    if (chktmp.Checked == true)
    {
        FileGenerator file = new FileGenerator();
        //path = file.GenerateFiles(ChargeCode);
        path = "asd";
        if (path == "")
        {
            path = file.GenerateAgain(ChargeCode);
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "getConfirmation", "getConfirmation(this, 'Please confirm','Are you sure you want to Generate Again?');",true);
        }

    }
    else
    {
        string message = "Please select confirm box";
        string header = "Info";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "LaunchServerSide", "openModal('" + message + "','" + header + "','');", true);
    }
}

文件生成后我想检查路径是否为空,当条件失败时,我会显示用户将选择确认或取消的弹出窗口,并且在该响应上我想执行其余代码。 任何帮助都会受到谴责。

1 个答案:

答案 0 :(得分:0)

循环网格。检查您的情况并禁用,如果为真。您可以稍后启用它们(删除按钮更改以生成或其他内容):

protected void Page_LoadComplete(object sender, EventArgs e){
    foreach(GridViewRow row in GridView1.Rows){
       ImageButton but = (ImageButton)row.FindControl("YourButtonID");           
       if(blabla){
         disableButton(but);
        }
    }
}
    private void disableButton(ImageButton btn_delete)
    {

        btn_delete.Enabled = false;
        btn_delete.ImageUrl = "~/Pics/delete_small_disabled.gif";
    }

    private void enableButton(ImageButton btn_delete)
    {

        btn_delete.Enabled = true;
        btn_delete.ImageUrl = "~/Pics/delete_small.gif";
    }