我有一个c#程序,它使用JavaScript confirm()函数创建是/否警报。
我遇到的问题是:
JavaScript的:
function Confirm()
{
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Are you sure you want to continue?"))
{
confirm_value.value = "Yes";
}
else
{
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
C#:
public void OnConfirm(object sender, EventArgs e)
{
try
{
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes")
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You selected yes.')", true);
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You selected no.')", true);
}
}
catch (Exception ex)
{
exceptionLabel.Text = (ex.Message);
}
}