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

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.

1
  • Just as an aside... out of context, the statement "Click OK or Cancel to Continue" sounds ambiguous. Perhaps it makes a lot more sense within the context of the page it will be displayed on. Consider revising the statement for clarity. (e.g., What will happen if I click OK? What will happen if I click Cancel?) Commented Aug 24, 2011 at 23:55

1 Answer 1

2

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;
        }
    }
Sign up to request clarification or add additional context in comments.

1 Comment

On a side note, no need to use a literal string here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.