ASP.net - 巴顿 - JavaScript的confirm对话框 - 执行一些服务器端code? [英] ASP.net - Button - Javascript Confirm dialog - execute SOME server-side code?

查看:86
本文介绍了ASP.net - 巴顿 - JavaScript的confirm对话框 - 执行一些服务器端code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的ASP.net页面,用户可以编辑有关自己的信息。

I have a simple ASP.net page where users can edit information about themselves.

在单击编辑按钮,形式进入编辑模式,我显示保存和取消按钮,它像预期的那样。

When "Edit" button is clicked, the form goes into edit mode and I display "Save" and "Cancel" buttons, which behave as expected.

我想要做的是这样的:

当点击保存,显示一个Javascript确认对话框,询问用户是否想发送电子邮件给其他用户,告知他们刚刚进行的更新。

When "Save" is clicked, display a Javascript Confirm dialog asking the user if they want to send an email to the other users to inform them of the update just made.

如果用户说好,然后执行所有服务器端code保存数据,并发送电子邮件。
如果用户说取消,然后执行所有服务器端code保存数据,不发送电子邮件。

If user says OK, then execute all server-side code to save the data, AND send an email. If user says Cancel, then execute all server-side code to save the data, WITHOUT sending the email.

所以,我需要的JavaScript对话框设置,然后可以读取服务器端的一个标志,不知为什么...然后我可以这样做:

So, I need the javascript box to set a flag which can then be read server-side, somehow... then I can do something like:

Sub btnSave_Click(sender, e) Handles btnSave.Click

    'Save all the data

    If sendEmail Then  'This flag set by reading result of javascript Confirm
        'Send the email
    End If

End Sub

我知道如何将一个确认框添加到该按钮的属性,并已经这样做了。我在寻找如何读取服务器端那个盒子的结果的答案......换句话说,我总是希望页回发的情况发生(从单击该按钮),但只有一些事件处理程序的code到执行。

I know how to add a Confirm box to the button Attributes, and have done so. I'm looking for an answer on how to read the result of that box on server side... in other words, I ALWAYS want the Page postback to happen (from clicking the button), but only SOME of the event-handler code to execute.

希望是有道理的。

感谢

推荐答案

创建一个隐藏字段,并设置现场的基础上,确认结​​果的价值。您还没有表现出对你的按钮或形式code / HTML,但你能适应这样的事情了进去:

Create a hidden field, and set the value of that field based on the result of the confirmation. You haven't shown the code/HTML for your button or form, but can you fit something like this into it:

<input type="hidden" id="sendEmail" name="sendEmail" value="" />

<input type="submit" value="Save" onclick="promptForEmail();" />

<script>
   function promptForEmail() {
      var result = Confirm("Send everybody an email?");
      // set a flag to be submitted - could be "Y"/"N" or "true"/"false"
      // or whatever suits
      document.getElementById("sendEmail").value = result ? "Y" : "N";
   }
</script>

这篇关于ASP.net - 巴顿 - JavaScript的confirm对话框 - 执行一些服务器端code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆