2011-08-24 73 views
2
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#中的消息框?Messagebox asp.net c#

approvalcount是int类型的变量。

如果你想返回值
+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; 
     } 
    } 
+0

请注意,在这里不需要使用文字字符串。 –

+0

感谢您的帮助。 – Shiran910029