Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a web form that has a cancel button on it. What I am trying to do is to click cancel to get redirected back to the Login page but it is not working. When the user clicks on Cancel the validations fire. Therefor stopping the redirect. How can I fix this?

C#
protected void Cancel_Click(object sender, EventArgs e)
    
    {
        Response.Redirect("Login.aspx");
    }
    }
Posted
Comments
Richard C Bishop 10-Apr-14 15:49pm    
Add this to your Redirect URL:

~/Login.aspx

and also set the CausesValidation Property to false on the cancel button.
Computer Wiz99 10-Apr-14 15:59pm    
Ok. Thanks. That worked!! Post as solution please.
Richard C Bishop 10-Apr-14 16:03pm    
Good, you are welcome. Posted.
Maciej Los 10-Apr-14 16:03pm    
My virtual 5!
I'd like to gie you a real 5. Please post it as a solution, Richard.
Murugesan22 10-Apr-14 15:54pm    
Post Source on the page

1 solution

Add this to your Redirect URL:
C#
Response.Redirect("~/Login.aspx");

and also set the CausesValidation property to false on the cancel button.
 
Share this answer
 
v2
Comments
Maciej Los 10-Apr-14 16:04pm    
5ed! As promised ;)
Richard C Bishop 10-Apr-14 16:06pm    
Thank you sir, too kind!
Maciej Los 10-Apr-14 16:43pm    
;)Please, do not call me "sir". That makes me feel older ;)
Richard C Bishop 10-Apr-14 16:48pm    
Fair enough, but what if I was vicariously "knighting" you?
Maciej Los 10-Apr-14 16:54pm    
OK, but on one condition: vicariously only ;)
:laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900