0

在我的 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*/
}

关于如何从确认框中获得是/否答案的任何想法?

4

2 回答 2

0

您正在注册的启动脚本将在显示网页时运行,在用户有机会与之交互之前。此时的确认提示可能会令人困惑。

更常见的是使用OnClientClick正在执行回发的按钮的属性:

<asp:Button ...
   OnClientClick="return confirm('Are you sure?');" 
/>

这样只有在用户尝试发帖时才会显示确认提示。

于 2013-02-18T14:09:18.333 回答
0

在表单上创建一个隐藏字段。用一些javascript在隐藏字段中写下问题的答案。读取后面代码中隐藏字段的值。

于 2013-02-18T13:56:19.783 回答