Solved

ASP.NET Cancel Button

Posted on 2013-01-04
4
423 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

827 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