Solved

ASP.NET Cancel Button

Posted on 2013-01-04
4
411 Views
Last Modified: 2013-01-04
Hello Experts,

I have a web application with a submit button and was asked to create another button called "Cancel". As dumn as it may sound I have never created a "Cancel" button and was wondering the best method to handle the "Cancel" button.

I would prefer a redirect when a user clicks the "Cancel" button if possible.
0
Comment
Question by:asp_net2
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
Jerry Miller earned 500 total points
ID: 38743986
If you are doing it in an UpdatePanel, Ajax makes it fairly easy:
http://msdn.microsoft.com/en-us/magazine/cc163380.aspx

When I am not using an UpdatePanel, I will cycle through the controls and set them back to defaults (textBoxes back to String.Empty, radioButtons unchecked, etc). Also turn off validation for the button using CauseValidation="false" to make sure that your users don't get annoying validation errors when trying to cancel the request.

Another way is to simply redirect the page back to itself, but only do that if there is nothing on the page where you would like the state to save.

Response.Redirect("Reports.aspx")
0
 
LVL 19

Expert Comment

by:Manoj Patil
ID: 38743994
Hey, this is something different requirement.
First tell me, what you are doing on Submit Button.
If you click on submit, page post back to server and finish the code execution written in Submit Button Event.
If within the certain amount of time, user click on cancel then you can revert the updates.
That is what you have to do..
Elaborate your question.
0
 
LVL 4

Author Comment

by:asp_net2
ID: 38744074
All,

I just need to redirect users back to Main page if they click on the "Cancel" button. So if a user DID enter data on the form and then clicks on "Cancel" I just want the page to get redirected to the main page with nothing getting added to DB. I fill make sure that I add CausesValidation=false on the Cancel button.
0
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 38744203
Rolling back database changes on a submit click gets a little more involved.

I generally disable the cancel button on submit click. My cancel buttons often are essentially reset buttons for the form.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

30 Experts available now in Live!

Get 1:1 Help Now