Solved

ASP.NET Cancel Button

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET MVC -Update model when click on <li> element 29 68
How to repeat the data 4 30
asp.net repeater 2 12
Import a excel sheet in a grid 2 10
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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