带有Checkbox的JQuery Dialog和C#中的Submit按钮

时间:2013-03-30 15:14:05

标签: c# javascript jquery asp.net validation

基本上我有一个JQuery UI对话框,但我需要在其中集成一个复选框和一个提交按钮。单击提交按钮关闭对话框后,我需要选中复选框。它与术语和条件相同。

有人会介意分享如何做/最佳方法吗?一直在寻找,但没有发现任何接近。

感谢。

<script type="text/javascript">
$(function() {
$("#dialog").dialog({
      autoOpen: true,
      closeOnEscape: false,
      resizable: false,
      draggable: false,
      height: 700,
      width: 700,
      modal: true,
      show: { effect: "fade", duration: 1000 }
      });
  });
  $(function() {
      $("#dialog").dialog({
          buttons: {
          Confirm: function() {
                  $(this).dialog("close");
              }
          }
      });
  });

<asp:CheckBox ID="CheckBox1" runat="server" />
  <asp:Button ID="Button2" runat="server" Text="Button" />

1 个答案:

答案 0 :(得分:1)

您可以最初禁用提交按钮,然后在选中复选框时切换是否启用:

$('#Button2').attr('disabled', true);

$("#dialog #CheckBox1").change(function() {
  $('#Button2').attr('disabled',!this.checked);
});

另外,我不太熟悉jQuery对话框为你插入按钮的能力,因为我使用的所有HTML都是由我们的设计师预先创建并使用自定义绑定框架,但看起来你同样使用pre生成的asp.net HTML。如果,所以我认为你不会使用jQuery对话框来生成按钮。相反,你会有如下代码:

$('#Button2').click(function() {
  // Submit code.  Possibly $.post() and $("#dialog").dialog('close')
  // or triggering the webform's postback.
});