[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

C#

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
0
tolninja
Asked:
tolninja
2 Solutions
 
Bill-HansonCommented:
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.
0
 
tolninjaAuthor Commented:
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
0
 
ToFroCommented:
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
        }
0
 
Dux11Commented:
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.
0
 
tolninjaAuthor Commented:
Thanks.  I ended up writing a function to loop through every control and set it equal to "" if it was a textfield, label, etc.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now