如何在C#代码中获得Confirm popup的响应? [英] How can I get response of Confirm popup in C# code?

查看:90
本文介绍了如何在C#代码中获得Confirm popup的响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码在C#代码中创建javascript弹出窗口,并希望在某些C#变量中保存用户的回复(OK / Cancel)。如果您有任何解决方案,请在此处发布。



I am using following code to create javascript popup in C# code and want to save reply of user (OK/Cancel) in some C# variable. If you have any solution, than please post it here.

Page.ClientScript.RegisterStartupScript(Page.GetType(), "Message Box", "<script language='javascript'> confirm('This is confirm popup')</script>");





谢谢



Thank you

推荐答案

一个想法是将隐藏字段放在表单中,并设置用户响应确认框的值。

让我们比如说,隐藏的字段是 -

One idea can be to put a hidden field in the form and set the value on user responding to the confirm box.
Lets say, the hidden field is -
<asp:hiddenfield id="hdnConf" runat="server" xmlns:asp="#unknown" />



现在,让我们相应地修改你的代码。


Now, let's modify your code accordingly.

Page.ClientScript.RegisterStartupScript(Page.GetType(), "Message Box", "<script language="'javascript'">if (confirm('This is confirm popup')) document.getElementById('<%=hdnConf.ClientID%>').value='true'; else document.getElementById('<%=hdnConf.ClientID%>').value='false';</script>");

//get confirmation value
bool confResult=bool.Parse(hdnConf.Value.ToString());





是纯粹未经测试的代码,因此您可能需要修改一下。



希望,它有帮助:)



This is purely untested code and hence you may need to modify a little.

Hope, it helps :)


这篇关于如何在C#代码中获得Confirm popup的响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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