c# - 消息框 asp.net c#

标签 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;
}

我需要上述代码的帮助。如果点击ok需要返回true或者点击cancel需要返回false。我怎样才能得到返回值?还有其他方法可以在 asp.net 和 c# 中显示消息框吗?

approvalcount 是整型变量。

最佳答案

如果你想返回值是客户端那么使用return关键字

  string script = @"return confirm('Click OK or Cancel to Continue') ;";

补充:
我想我误解了你的问题。你想要客户端 true |服务器端的错误值。它可以通过 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;
        }
    }

关于c# - 消息框 asp.net c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7178819/

相关文章:

c# - 是否有关于使用 C# 客户端创建 C++ 聊天服务器的文章或建议?

asp.net - IIS7、SSL 和 "The page was not displayed because the request entity is too large."

c# - 在事件触发 SqlDependency 后获取 Context.User.Identity.Name Null

c# - VS 2010 中的模糊引用

c# - C# 中的泛型对象

c# - 如何使用 C++ 静态库编译 C# 应用程序?

asp.net - IIS url 重写,损坏的 href(css、js 等)

c# - 用户退出时的 Safari OnUnload 事件

asp.net - 在 Active Directory 中创建用户时 RPC 服务器不可用

c# - 在 VS SETUP 项目中更改目标文件名