Posted on 2007-08-03
Last Modified: 2013-11-05
Is there a way to reset a usercontrol so that it is in it's orriginal state?  For instance... I have a usercontrol that has textfields, comboboxes, checkboxes, and an assortment of other items that get modified by the user.  Once the user clicks the 'submit' button I would like to reload that single control so that all of the fields that were modified are now in their orriginal state.  Oh... and this is for a WINDOWS APP.  thx
Question by:tolninja
    LVL 22

    Accepted Solution

    Sorry, no.

    If you need that functionality, you will need to design it yourself.  Just add a method that sets the individual controls to a pre-defined state.  Or create a method that saves the default state, then another method to restore that state.
    LVL 1

    Author Comment

    Thanks for the quick reply.  That's what I figured... I'm going to leave the question open for a little while longer just incase someone has a better solution.  thx
    LVL 6

    Assisted Solution

    I think Bill-Hanson is 100% right about this one. If you want the controls to reset to an original state, you will have to store original values for all the controls and reset them manually in a method.

    Here is a really simple example:

            // These constant variables should be declared globally in the class.
            private const Boolean DEFAULT_RECEIVE_NEWSLETTER = true;
            private const String DEFAULT_EMAIL_ADDRESS  = "";
            private const Int32 DEFAULT_AGE = 25;

            // Run this method to Reset the controls to the default values
            private void ResetControls()
                chkReceiveNewsletter.Checked = DEFAULT_RECEIVE_NEWSLETTER;            // CheckBox
                txtEmail.Text = DEFAULT_EMAIL_ADDRESS;                                                     // TextBox
                cmbAge.SelectedIndex = cmbAge.FindString(DEFAULT_AGE.ToString());       // ComboBox
    LVL 1

    Expert Comment

    Sorry I dont have code to help but if I could add one extra suggestion to the above and that is to instead of creating all of the constants hard coded, I would instead have Main call a function to store the default values this way changes in the IDE wont get changed by the constants, changes will propegate through.
    LVL 1

    Author Comment

    Thanks.  I ended up writing a function to loop through every control and set it equal to "" if it was a textfield, label, etc.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    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…
    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…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    746 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

    13 Experts available now in Live!

    Get 1:1 Help Now