简体   繁体   English

客户端是/否确认消息,然后再插入

[英]Client Side Yes/No confirmation message before inserting

I have an application that adds a form to the database (ASP.NET 2.0) 我有一个将表单添加到数据库(ASP.NET 2.0)的应用程序

The button emits SqlDataSource_3_Inserting & SqlDataSource_3_Inserted . 该按钮将发出SqlDataSource_3_InsertingSqlDataSource_3_Inserted

I must find a way to look if the field X in the database is over the average. 我必须找到一种方法来查看数据库中的字段X是否超过平均值。 This method is called IsCorrectAmmounts() and returns a bool. 此方法称为IsCorrectAmmounts()并返回布尔值。

If bool is true, THEN the user must confirm that the ammount is OK. 如果bool为true,则用户必须确认该数量是可以的。 If it is (eq Yes), then the datas are inserted in the database, and the admin must be notified (STMP Email) that the user has add a value over average (method has already been made, NotifyAdmin() ) 如果是(即是),则将数据插入数据库中,并且必须通知管理员(STMP电子邮件)用户添加的值超出平均值(方法已经制定, NotifyAdmin() )。

With ALL that said: 上面写着:

How to make a confirmation box AFTER the IsCorrectAmmounts gets executed and how to make the yes response submit (eq Inserting) the form? IsCorrectAmmounts执行后,如何在确认框中显示IsCorrectAmmounts如何使Yes响应提交(即插入)表格?

"AFTER the IsCorrectAmmounts gets executed" add the following code: “在IsCorrectAmmounts被执行之后”添加以下代码:

if (confirm('hey user, is this amount ok?')) {
    yourForm.submit();
}

I created a Fiddle for you that demonstrates what you want! 我为您制作了一个小提琴 ,展示了您想要的东西!

The HTML... HTML ...

<form id='confirmationForm' action='/your/url' method='post'>
    <input id='confirmation' name="confirmation" type="hidden" value="" />
</form>​

JavaScript code... JavaScript代码...

function IsCorrectAmmounts() {
    return true;
}

if (IsCorrectAmmounts()) {
   var result = confirm('Is the amount correct')
     , form = document.getElementById('confirmationForm')
     , input = document.getElementById('confirmation');

    if (result) {
        input.value = result;
        form.submit();
    }
}​

Here is Fiddle with an AJAX version of the same code using jQuery. 这是Fiddle,其中包含使用jQuery的相同代码的AJAX版本。

function IsCorrectAmmounts() {
    return true;
}

if (IsCorrectAmmounts()) {
   var result = confirm('Is the amount correct');

   if (result) {
       $.post('/your/url', { "result": result }, function () {           
           alert('submitted');
       });
    }
}​

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM