Solved

Reset button functionality in C#

Posted on 2004-10-25
680 Views
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
0
Question by:anagm
    5 Comments
     
    LVL 3

    Expert Comment

    by:aacool
    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

    thus,
    private string m_origName,m_origAddress,m_origZip;
    private bool m_flg=false;
    ...
    public void OnLoad(...)
    {
       loadFields(...);
        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(...)
    {
      if(m_flg==true)
      {
       Name.Text = m_origName;
       Address.Text = m_origAddress;
       Zip.Text = m_origZip;
      }
    }

    Please tell me if this helps
    0
     
    LVL 18

    Accepted Solution

    by:
    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
    0
     

    Author Comment

    by:anagm
    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
    0
     

    Author Comment

    by:anagm
    armoghan, can you give an example
    0
     
    LVL 18

    Expert Comment

    by:armoghan
    You need to implement ICloneable Interface on the object.
    see this as a start up
    http://www.ondotnet.com/pub/a/dotnet/2002/11/25/copying.html?page=2

    see the reference of IConeable from MSDN
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemicloneableclasstopic.asp

    see this example for generic method of cloning.
    http://www.codeproject.com/csharp/cloneimpl_class.asp

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

    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