在我的C#代码中,我使用以下代码向用户显示了一个确认框:
string confirmMsg = "All the cause data will be permanently removed. Are you sure you want to continue";
ClientScript.RegisterStartupScript(Page.GetType(), "TWCL Issue Mgmt System", "confirm('" + confirmMsg + "');", true);
我正在尝试将答案(是或否)放入布尔值或其他变量中,这样我就可以根据给定的答案执行其他代码。所以我想要这样的东西:
bool x = ClientScript.RegisterStartupScript(Page.GetType(), "TWCL Issue Mgmt System", "confirm('" + confirmMsg + "');", true);
if(x)
{
/*Exceute the rest of the code here*/
}
else
{
/*do postback*/
}
关于如何从确认框中获得是/否答案,您有什么想法吗?
发布于 2013-02-18 21:56:20
在表单上创建隐藏字段。用一些javascript将问题的答案写在隐藏字段中。读取后面代码中隐藏字段的值。
发布于 2013-02-18 22:09:18
您正在注册的启动脚本将在显示网页时运行,此时用户尚未有机会与其进行交互。
更常见的做法是使用执行回发的按钮的OnClientClick
属性:
<asp:Button ...
OnClientClick="return confirm('Are you sure?');"
/>
https://stackoverflow.com/questions/14937957
复制相似问题