Is there any way to get the old value of a control

I have a simple form with a text box and a button.. On display the text box will be loaded with some data from DB and the user can change and submit it back to the server.. Now i will get the new value of text from the textbox's Text property but is there anyway I can get the old value too.. from the viewstate or somewhere??


 


If this post was useful to you, please mark it as answer.

ClientSideAsp.Net | Blog
0
anzer
4/19/2009 7:55:04 AM
asp.net.free-for-all 9281 articles. 0 followers. Follow

4 Replies
505 Views

Similar Articles

[PageSpeed] 22

 You can follow one of the following approaches-

1. Define a hidden control alongside your textbox in the following way-

<asp:Hidden  id="oldTextBoxContent" runat="Server"/>

then when setting the textbox's value from db, set the same value in the hidden control-

textBox.Text = "value from db";

 oldTextBoxContent.value = "value from db";

Then, on the post back, you can use  oldTextBoxContent.value to find the old value of the textbox.

If you need this in many text boxes of your application, you can encapsulate this hidden-textbox couple in a user control. Then in the user control provide two properties, OldValue and NewValue. This will hide the details of implementation as well as implement code reuse.

2. You can use session to persist the old value in the server.

3. If you are taking the old value from database, you can simply read the value again before updating!

Please mark as answer if it helps.


--
(Please, Mark as Answer if it Helped)
http://smsohan.blogspot.com
0
sohan
4/19/2009 8:22:46 AM

anzer:
I have a simple form with a text box and a button.. On display the text box will be loaded with some data from DB and the user can change and submit it back to the server.. Now i will get the new value of text from the textbox's Text property but is there anyway I can get the old value too.. from the viewstate or somewhere??

 

Create a ViewState variable and store the values of TextBoxes in it before assigning new values from database

 


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
4/19/2009 8:52:56 AM

Currently am using ViewState variables to achieve this functionality.. But some of my forms are so big and showing lots of data in it,, some of them are multiline rich texts.. so storing all these data in ViewState variables just to compare with new value has a big performance impact..

I was wondering is there any other way to achieve this functionality other than storing in hidden/viewstate or retrieving data again from database and compare...



If this post was useful to you, please mark it as answer.

ClientSideAsp.Net | Blog
0
anzer
4/19/2009 7:44:14 PM

You can also get the previous textbox values in Request.form collection

just save that complete string smewhere and you can then split it to get the values. Though a different topic I have described the same here

how to get values from Requesst.Form

http://aspsnippets.com/post/2009/03/01/Dynamic-Controls-Made-Easy-ASPNet.aspx


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
4/20/2009 6:24:59 AM
Reply: