Messagebox asp.net c#

时间:2011-08-24 16:17:02

标签: c# asp.net

int approvalcount; 
if (approvalcount > 0)
{
    string script = @"confirm('Click OK or Cancel to Continue') ;";
    ScriptManager.RegisterStartupScript(this, this.GetType(), "confirm_entry", script, true);
}
else
{
    return true;
}

我需要上述代码的帮助。如果单击确定需要返回true或单击取消需要返回false。我如何获得返回值?有没有其他方法可以在asp.net和c#中显示消息框?

approvalcount是int类型变量。

1 个答案:

答案 0 :(得分:2)

如果要返回值是客户端,请使用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;
        }
    }