0

I have a wizard control. On one of its pages I have various controls like textboxes and checkboxes. Could anybody please tell me how I can check from my code (e.g. on Cancel) if the contents of the controls has been changed? I know how to check if each control was changed separately, but is there any way to check the page as a whole?

2
Contributors
6
Replies
7
Views
8 Years
Discussion Span
Last Post by dpreznik
0

hope this helps...

public static void ClearForm(System.Windows.Forms.Control parent)
        {
                foreach (System.Windows.Forms.Control ctrControl in parent.Controls)
                {
                    //Loop through all controls

                 if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.TextBox)))
                 {
                      //Check to see if it's a textbox
                      ((System.Windows.Forms.TextBox)ctrControl).Text = string.Empty;
                            //If it is then set the text to String.Empty (empty textbox)
                  }
                  else if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.RichTextBox)))
                  {
                       //If its a RichTextBox clear the text
                       ((System.Windows.Forms.RichTextBox)ctrControl).Text = string.Empty;
                  }
                  else if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.ComboBox)))
                  {
                       //Next check if it's a dropdown list
                       ((System.Windows.Forms.ComboBox)ctrControl).SelectedIndex = -1;
                            //If it is then set its SelectedIndex to 0
                  }
                  else if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.CheckBox)))
                  {
                       //Next uncheck all checkboxes
                       ((System.Windows.Forms.CheckBox)ctrControl).Checked = false;
                  }
                  else if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.RadioButton)))
                  {
                       //Unselect all RadioButtons
                       ((System.Windows.Forms.RadioButton)ctrControl).Checked = false;
                  }
                  if (ctrControl.Controls.Count > 0)
                  {
                      //Call itself to get all other controls in other containers
                      ClearForm(ctrControl);
                  }

For the aboove code, instead of making it empty, I would check to see if there is anything inside of them and loop through with a flag(boolean) and run a check at the end.

0

Thanks, it did help. I still have problem though. Here is how I use it:

protected void OnValueChanged(object sender, EventArgs e)
        {
            ViewState["IsModified"] = true;
        }

        protected void SubscribeForOnChange(Control parent)
        {
            foreach (Control ctrControl in parent.Controls)
            {
                //Loop through all controls
                if (object.ReferenceEquals(ctrControl.GetType(), typeof(TextBox)))
                {
                    ((TextBox)ctrControl).AutoPostBack = true;
                    ((TextBox)ctrControl).TextChanged += new EventHandler(OnValueChanged);
                }
...
            }
        }

I call this method from my custom code behind parent class' Page_Load:

protected void Page_Load(object sender, EventArgs e)
        {            
            if (!IsPostBack && wizSummaryDetails.ActiveStep == wizStepSummary)
            {
                ViewState["IsModified"] = false;
                SubscribeForOnChange(this);
...

But when I run the application and change the value in the textbox, I do not come to OnValueChanged(). Could you explain why it doesn't happen?

Thank you very much,
Dmitriy

0

I'm still learning all the bells and whistles of ASP-C#... but I'll give a shot..

Two things
1) Set up an auto-refresh in the meta tag
or
2) Check to make sure the OnValueChanged is called somehow when the button is clicked... if it is not already activated.

0

Could you please tell me more about 1) because I don't really know anything about it. Where and how that should be done?
2) With a button, OnValueChanged() is called.

0

sure... in the meta tag at the top of the html.... insert this between the <head></head> tags

<meta http-equiv="refresh" content="x">

where you replace x with how many seconds you want to wait before you refresh

0

Thanks.
But my textboxes are in the second wizard's step, and on refreshing I get to the first step. Plus, I just don't get why it doesn't work on simple changing the textbox's content? If I subscribe for the TextChanged event through the designer, it works. But not when I do it programmatically.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.