How to check if page has been modified?

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2009
Posts: 26
Reputation: dpreznik is an unknown quantity at this point 
Solved Threads: 0
dpreznik dpreznik is offline Offline
Light Poster

How to check if page has been modified?

 
0
  #1
Jul 9th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 37
Reputation: redburn is an unknown quantity at this point 
Solved Threads: 8
redburn's Avatar
redburn redburn is offline Offline
Light Poster

Re: How to check if page has been modified?

 
0
  #2
Jul 9th, 2009
hope this helps...
  1. public static void ClearForm(System.Windows.Forms.Control parent)
  2. {
  3. foreach (System.Windows.Forms.Control ctrControl in parent.Controls)
  4. {
  5. //Loop through all controls
  6.  
  7. if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.TextBox)))
  8. {
  9. //Check to see if it's a textbox
  10. ((System.Windows.Forms.TextBox)ctrControl).Text = string.Empty;
  11. //If it is then set the text to String.Empty (empty textbox)
  12. }
  13. else if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.RichTextBox)))
  14. {
  15. //If its a RichTextBox clear the text
  16. ((System.Windows.Forms.RichTextBox)ctrControl).Text = string.Empty;
  17. }
  18. else if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.ComboBox)))
  19. {
  20. //Next check if it's a dropdown list
  21. ((System.Windows.Forms.ComboBox)ctrControl).SelectedIndex = -1;
  22. //If it is then set its SelectedIndex to 0
  23. }
  24. else if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.CheckBox)))
  25. {
  26. //Next uncheck all checkboxes
  27. ((System.Windows.Forms.CheckBox)ctrControl).Checked = false;
  28. }
  29. else if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.RadioButton)))
  30. {
  31. //Unselect all RadioButtons
  32. ((System.Windows.Forms.RadioButton)ctrControl).Checked = false;
  33. }
  34. if (ctrControl.Controls.Count > 0)
  35. {
  36. //Call itself to get all other controls in other containers
  37. ClearForm(ctrControl);
  38. }

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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 26
Reputation: dpreznik is an unknown quantity at this point 
Solved Threads: 0
dpreznik dpreznik is offline Offline
Light Poster

Re: How to check if page has been modified?

 
0
  #3
Jul 9th, 2009
Thanks, it did help. I still have problem though. Here is how I use it:

  1. protected void OnValueChanged(object sender, EventArgs e)
  2. {
  3. ViewState["IsModified"] = true;
  4. }
  5.  
  6. protected void SubscribeForOnChange(Control parent)
  7. {
  8. foreach (Control ctrControl in parent.Controls)
  9. {
  10. //Loop through all controls
  11. if (object.ReferenceEquals(ctrControl.GetType(), typeof(TextBox)))
  12. {
  13. ((TextBox)ctrControl).AutoPostBack = true;
  14. ((TextBox)ctrControl).TextChanged += new EventHandler(OnValueChanged);
  15. }
  16. ...
  17. }
  18. }
I call this method from my custom code behind parent class' Page_Load:
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. if (!IsPostBack && wizSummaryDetails.ActiveStep == wizStepSummary)
  4. {
  5. ViewState["IsModified"] = false;
  6. SubscribeForOnChange(this);
  7. ...
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
Last edited by peter_budo; Jul 10th, 2009 at 6:19 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 37
Reputation: redburn is an unknown quantity at this point 
Solved Threads: 8
redburn's Avatar
redburn redburn is offline Offline
Light Poster

Re: How to check if page has been modified?

 
0
  #4
Jul 9th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 26
Reputation: dpreznik is an unknown quantity at this point 
Solved Threads: 0
dpreznik dpreznik is offline Offline
Light Poster

Re: How to check if page has been modified?

 
0
  #5
Jul 9th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 37
Reputation: redburn is an unknown quantity at this point 
Solved Threads: 8
redburn's Avatar
redburn redburn is offline Offline
Light Poster

Re: How to check if page has been modified?

 
0
  #6
Jul 9th, 2009
sure... in the meta tag at the top of the html.... insert this between the <head></head> tags

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

where you replace x with how many seconds you want to wait before you refresh
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 26
Reputation: dpreznik is an unknown quantity at this point 
Solved Threads: 0
dpreznik dpreznik is offline Offline
Light Poster

Re: How to check if page has been modified?

 
0
  #7
Jul 9th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC