Reset button functionality in C#

Posted on 2004-10-25
Medium Priority
Last Modified: 2008-02-01
I am trying to implement the following

Name     Address   ZipCode

x            Jackson    132                 Edit     Reset
(the above data is default)
I make the changes with 'Edit' Button

Name     Address   ZipCode

x            Simpson    456                 Edit     Reset
When i press the 'Reset' Button, i should get the following(should change to the default values)

Name     Address   ZipCode

x            Jackson    132                 Edit     Reset

How do i tackle this one?

Any help is appreciated.  Its urgent

My application is in ASP.NET and C#.

Can i get an example code
Question by:anagm
  • 2
  • 2

Expert Comment

ID: 12406295
It's not clear how or when this data is loaded into what kind of data structure - are these just fields or a list view or...?

In any case, the principle should be to maintain a set of corresponding variables in your load method that keep the original values, and then to load the values back in the Reset method

private string m_origName,m_origAddress,m_origZip;
private bool m_flg=false;
public void OnLoad(...)
    m_origName = Name.Text;
    m_origAddress = Address.Text;
    m_origZip = Zip.Text;
    m_flg = true; //set flag to indicate we have original values stored

public void OnReset(...)
   Name.Text = m_origName;
   Address.Text = m_origAddress;
   Zip.Text = m_origZip;

Please tell me if this helps
LVL 18

Accepted Solution

armoghan earned 1500 total points
ID: 12407497
How I do is, make a clone of the object which you have populated. User can change the object, but when he/she presses the reset button, as you have saved the clone copy, populate it once again

Author Comment

ID: 12410519
The data(original values) are loaded into a grid, when the page is initialized.

The original values is a record in the database and it is the first record, with description 'default'.

i am using the <itemtemplates> to load the data into the grid

Author Comment

ID: 12412414
armoghan, can you give an example
LVL 18

Expert Comment

ID: 12418679
You need to implement ICloneable Interface on the object.
see this as a start up

see the reference of IConeable from MSDN

see this example for generic method of cloning.

Now you keep a copy on server side or Session and reset to it when required

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Watch the video to learn how one can deal with PST file corruption issue with an outstanding Kernel for Outlook PST Repair Tool easily. Using this tool, non-technical users can swiftly perform the repair process to restore their essential data witho…
Suggested Courses

600 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