?
Solved

ASP.NET Cancel Button

Posted on 2013-01-04
4
Medium Priority
?
427 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
Jerry Miller earned 2000 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

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

777 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