Reset button functionality in C#

Posted on 2004-10-25
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
    LVL 3

    Expert Comment

    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

    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

    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

    armoghan, can you give an example
    LVL 18

    Expert Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    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

    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    In this Experts Exchange video Micro Tutorial, I'm going to show how small business owners who use Google Apps can save money by setting up what is called a catch-all email address in their Gmail accounts. By using the catch-all feature, small busin…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    875 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

    8 Experts available now in Live!

    Get 1:1 Help Now