为什么弹出窗口会在复选框单击事件时消失?

时间:2017-02-27 06:21:15

标签: c# asp.net .net c#-4.0 webforms

我在模板字段中使用了面板,当我勾选复选框时它会消失。

我试过修理它但仍然消失了。代码在调试时运行良好,但显然不是。如果可以的话请帮忙。我已经花了很多时间在它上面。

 <asp:TemplateField HeaderText='Finalized ?'>
  <ItemTemplate>
   <asp:LinkButton ID="btnFinalizedRecord" OnClick="btnFinalizedRecord_Click" runat="server" Text='<%# Convert.ToBoolean(Eval("IsFinalized")) == true? "Already Finalized": "Finalize" %>'
                                CssClass="" ToolTip="Finalize" CommandName="Finalize"
                                CommandArgument='<%#Eval("IsFinalized")%>' Enabled='<%# Convert.ToBoolean(Eval("IsFinalized")) == true? false: true %>'></asp:LinkButton>
     <ajax:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" DisplayModalPopupID="mpe2" TargetControlID="btnFinalizedRecord">
     </ajax:ConfirmButtonExtender>
     <ajax:ModalPopupExtender ID="mpe2" runat="server" PopupControlID="pnlPopup2" TargetControlID="btnFinalizedRecord" OkControlID="btnYes"
                                CancelControlID="btnNo" BackgroundCssClass="modalBackground">
      </ajax:ModalPopupExtender>
      <asp:Panel ID="pnlPopup2" runat="server" CssClass="modalPopup" Style="display: none">
      <div class="header">
        Confirmation
      </div>
      <div class="body">
        Are you sure to <b>Finalize</b>? 
       <asp:CheckBox ID="chkConfirmFinalize" runat="server" AutoPostBack="true" OnCheckedChanged="chkConfirmFinalize_CheckedChanged" />
        <br />
        You will not be able to perform an edit after finalizing.
      </div>                                        
      <div class="Popupfooter" align="right">
       <asp:Button ID="btnYes" Enabled="false" CssClass="btn btn-sm btn-danger" runat="server" Text="Yes" />
       <asp:Button ID="btnNo" CssClass="btn btn-sm btn-primary" runat="server" Text="No" />
      </div>
     </asp:Panel>
    </ItemTemplate>
  </asp:TemplateField>

的.cs:

    protected void chkConfirmFinalize_CheckedChanged(object sender, EventArgs e)
    {
        try
        {
            var chkConfirmFinalize = sender as CheckBox;
            GridViewRow gr = (GridViewRow)chkConfirmFinalize.NamingContainer;
            Panel pnlPopup2 = gr.FindControl("pnlPopup2") as Panel;
            if (chkConfirmFinalize.Checked == true)
            {
                btnYes.Visible = true;
            }
            else 
            {
                btnYes.Visible = false;
            }
            pnlPopup2.Visible = true;
        }
        catch (Exception ex)
        {
            Utility.Msg_Error(Master, ex.Message);
        }
    }

1 个答案:

答案 0 :(得分:0)

使用AutoPostBack,您可以在复选框时重新加载页面(转到服务器并返回),这就是面板消失的原因。 您应该尝试使用javascript与&#34; onclick&#34;事件

<asp:CheckBox ID="chkConfirmFinalize" runat="server" OnClick="somefunction(this)" />

在jquery中显示按钮:

function somefunction(element) {
    if ($element.val() == true) {
        $("#btnYes").prop('disabled', false);
    } else {
        $("#btnYes").prop('disabled', true);
    }
}