带响应的服务器端确认消息框 [英] Server side confirmation message box with response

查看:64
本文介绍了带响应的服务器端确认消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,

我想做什么

1.我点击一个按钮。

2.在btn_Click上执行一些代码事件。

3.在代码中有特定条件(如if(a == b)),打开确认消息框,除非我在确认框中单击确定/取消按钮,否则请勿继续操作。



我尝试过:



ClientScript.RegisterStartupScript(这个。 GetType(),script,确认('你想继续吗?');,真实);



但我怎样才能得到回应并执行进一步对是或否。

Hello All,
What I want to do this
1.I click a button.
2.Execute some code on btn_Click event.
3.At certain condition in code (like if(a==b)), open Confirmation message box, Do not proceed further unless and until I click Ok/Cancel button on confirmation box.

What I have tried:

ClientScript.RegisterStartupScript(this.GetType(), "script", "confirm('DO YOU WANT TO CONTINUE?');", true);

but how can i get response and execute further on either yes or no.

推荐答案

它不能像那样工作。

服务器代码组装HTML以及何时完成发送它给客户。然后,服务器应用程序有效地完全停止运行,直到它从客户端获得用户与之交互的信号。然后它再次加载整个页面(我忽略了Ajax,这里需要一些捷径)并遵循说明。



你不能发送消息在HTML的中间组装中给客户端并让服务器代码等待他在执行继续之前做出响应 - 它只是不能那样工作。这仅适用于可以使用MessageBox的单机应用程序。并且MessageBox不起作用 - 虽然它似乎在开发中 - 因为在生产中服务器和客户端是独立的机器,并且C#代码只在服务器上运行:因此MessageBox将出现在客户端可以的服务器上'读它。

Javascript代码在客户端上运行,因此您可能希望在那里进行确认,而不是在C#中:窗口确认()方法 [ ^ ]
It doesn't work like that.
The server code assembles HTML and when it's complete sends it to the client. The server app then effectively stops running completely until it gets a signal from the client that the user has interacted with it. It then loads the whole page again (I'm ignoring Ajax which takes some "short cuts" here) and follows the instructions.

You can't send a message to the client in mid assembly of the HTML and have the server code wait for him to respond before execution continues - it just doesn't work like that. That's is only for single machine applications, where you can use MessageBox. And MessageBox won't work - although it may seem to in development - because in production the server and client are separate machines, and C# code is only ever run on the server: so the MessageBox would appear on the server where the Client can't read it.
Javascript code is run on the client, so you probably want to do your confirmation there, rather than in C#: Window confirm() Method[^]


要求用户确认他们想继续执行某个操作ASP.NET论坛 [ ^ ]


这篇关于带响应的服务器端确认消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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