Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reset button functionality in C#

Posted on 2004-10-25
5
Medium Priority
?
733 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
Comment
Question by:anagm
[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
  • 2
5 Comments
 
LVL 3

Expert Comment

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

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

Author Comment

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

Author Comment

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

Expert Comment

by:armoghan
ID: 12418679
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

610 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