是客户端,然后使用return
关键字
string script = @"return confirm('Click OK or Cancel to Continue') ;";
增加:
我想我误解你的问题。你希望客户端是真的|服务器端的错误值。它可以通过certian调整..可实现以下是代码
protected void Page_Load(object sender, EventArgs e)
{
bool a = false; //initialize the default value
//this will be called later
if (Request["val"] != null)
{
if (Request["val"].ToString() == "true")
a = true;
else
a = false;
}
else
{
// this will be called first
a = somefunction();
}
}
public bool somefunction()
{
int approvalcount = 1;
if (approvalcount > 0)
{
string script = @" if(confirm('Click OK or Cancel to Continue')) {
document.location='default.aspx?val=true';
} else {
document.location='default.aspx?val=false';
}";
ScriptManager.RegisterStartupScript(this, this.GetType(), "confirm_entry", script, true);
return false;
}
else
{
return true;
}
}
只是作为一个搁置...断章取义,语句“点击确定或取消以继续”的声音含糊不清。也许它会在显示页面的上下文中更有意义。考虑修改声明以求清楚。 (例如,如果单击“确定”会发生什么情况?如果单击“取消”,会发生什么情况?) –