0

仅在某些条件下,事件触发时如何要求确认?我在服务器端工作,我只想在我的布尔值为真时要求确认。

4

2 回答 2

1

如何在 ASP.Net Gridview 中添加“确认删除”选项?

好的,假设您在模板列中有一个带有按钮的网格

<asp:Button ID="btnSave" runat="server" Text="Save" OnClientClick="return check();" />

并在您的检查功能中写入确定按钮是否应该引发回发?

<script type="text/javascript">

function check() {

  var doINeedToAskUserConfirmation =  // Get this according to your needs
  if ( doINeedToAskUserConfirmation  ){
      return confirm("Are you sure?");
  }
  return true;
}

</script>

假设你有一个按钮

<input type="button" id="btnConfirm" value="Proceed"/>

进行 ajax 调用以确定是否需要任何确认。

$("#btnConfirm").click(function(){

   $.ajax({
     type: "POST",
     url: "some.ashx",
     data: { name: "John", location: "Boston" }
  }).done(function( response ) {
     // lets say when response is true we will ask confirmation
     if ( msg )
     {
        var c = confirm( "All record will be deleted. Are you sure ? ");
        // Do another ajax call to complete your operation
     }
  });


});
于 2013-01-09T17:21:00.410 回答
0

根据您使用的事件类型,您可以创建一个派生自EventArgs您的条件的类,并将其作为属性(例如称为 MyCondition)放在您自己的类中。

在事件处理方法中,您可以使用

if(e.MyCondition)
{
  // do something
}

编辑:根据您的评论,我建议您尝试使用DetailsView进行编辑,或者如果您愿意,可以使用 GridViews 编辑模式。
您还可以查看CustomValidator

于 2013-01-09T16:56:53.637 回答