Tracking data change - ViewState??
-
Hi, I'm fairly new to .NET and I have a problem that I've been trying to resolve for days now and haven't been able to find a solution. Briefly, I have a web page with a number of dropdownlist and textbox controls and a datagrid at the bottom of the page which I want to use to record the history. The idea is that a user enters data and then hits the "save" button on the page. At each save I create a new row on the grid. What I want to do is find out which field(s) have changed since the page was loaded or since the last save and record those field names in the history. I've read a lot about ViewState. I thought that if the page and controls have the EnableViewState property enabled then ViewState should automatically track the state of these controls. I assumed then that in my save routine, I could uses something like ViewState.IsItemDirty(myControlName) to find out if a certain field has changed, since the last save/page load. But I can't get this to work!!! ViewState.Count is 0! Do I have to add records to ViewState manually and then during Save, compare each field value with the value stored in ViewState to see if it has changed? If so then what is the purpose of the EnableViewState property. Is there a more elegant way of doing this? Shakeel
-
Hi, I'm fairly new to .NET and I have a problem that I've been trying to resolve for days now and haven't been able to find a solution. Briefly, I have a web page with a number of dropdownlist and textbox controls and a datagrid at the bottom of the page which I want to use to record the history. The idea is that a user enters data and then hits the "save" button on the page. At each save I create a new row on the grid. What I want to do is find out which field(s) have changed since the page was loaded or since the last save and record those field names in the history. I've read a lot about ViewState. I thought that if the page and controls have the EnableViewState property enabled then ViewState should automatically track the state of these controls. I assumed then that in my save routine, I could uses something like ViewState.IsItemDirty(myControlName) to find out if a certain field has changed, since the last save/page load. But I can't get this to work!!! ViewState.Count is 0! Do I have to add records to ViewState manually and then during Save, compare each field value with the value stored in ViewState to see if it has changed? If so then what is the purpose of the EnableViewState property. Is there a more elegant way of doing this? Shakeel
You don't need to use ViewState for just static controls on the page. ASP.NET does all the work for you. If you have a textbox on the page and you need to find out if the text changed that's what the TextChanged event is for. You need to write a handler for that event. Same for dropdownlists: SelectedIndexChanged event.