开发者

Messagebox asp.net c#

int approvalcount; 
if (approvalcount > 0)
{
    string script = @"confirm('Click OK or Cancel to Continue') ;";
    ScriptManager.RegisterStartupScript(this, this.GetType(), "confir开发者_如何学编程m_entry", script, true);
}
else
{
    return true;
}

I need help for the above code. If click ok need to return true or click cancel need to return false. How can I get the return value ? Are there any other ways to shows the message box in asp.net and c# ?

approvalcount is int typed variable.


if you want to return the value is client side then use return keyword

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

Addition :
I think I misunderstood your question. You want the client side true | false value in server side. It can be achieved by certian tweaks.. below is the code

    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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜