带响应的服务器端确认消息框

编程入门 行业动态 更新时间:2024-10-28 00:27:08
本文介绍了带响应的服务器端确认消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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论坛 [ ^ ]

更多推荐

带响应的服务器端确认消息框

本文发布于:2023-11-24 21:35:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626932.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:服务器端   消息

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!