Solved

ASP.NET Cancel Button

Posted on 2013-01-04
4
408 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

7 Experts available now in Live!

Get 1:1 Help Now