 |
| ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 17th, 2004, 03:32 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
how do i get the first viewstate of the page ...
hi all,
i need to get the first viewstate of the page controls
i have modified one textbox control and i need to get the original value, i noticed that reset button can reset all controls and retrieve these values, but how can i get this values by code to compare it with the entered values.
Ahmed Ali
Software Developer
__________________
Ahmed Ali
Senior Software Developer
|
|

January 18th, 2004, 12:40 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
If you want to save the very first value of any control that is changed, you'll need to save it off manually. You can access the viewstate collection when the page is first loaded. I'd recommend doing this in a handler for the PreRender event of the page so that you capture anything that happens in the page lifecycle. This is one of the last events that fires before the viewstate is saved. Save the values conditionally based on the postback.
If Not IsPostback Then
ViewState.Item("<key>") = <value>
End If
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

January 18th, 2004, 07:24 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
but how can the reset button get these values
ex. if you modify any data and click reset button all data retrieved without hitting the server (it's not refresh)
Ahmed Ali
Software Developer
|
|

January 18th, 2004, 03:15 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
If you actually want to keep those values clientside so you can "reset" the form, then you'll need to come up with some javascript to handle it. You could create a two dimensional javascript array to store a lookup table of all the values you will need for the "reset". Then you'll need to call a function that looks thru the array and sets the fields to all the original values. Store the complete .net clientID of the control and the value. Then you can just loop thru all the elements of that array and set the value of the named controls.
Probably a MUCH easier way to do this, even though it would mean a hit to the server is to use a regular asp:button and have it do a response redirect back to the same page. This would reset the whole page back to the pre-postback condition (assuming that one of those postbacks didn't save values which would then be displayed).
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

January 19th, 2004, 02:20 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thx Peter ,
but i was not asking, i was querying about how the reset button added from the html controls Set Return the original data to controls
Ahmed Ali
Software Developer
|
|

January 19th, 2004, 03:16 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Ok, I re-read your first post and may understand your question better.
The standard HTML "reset" button just sets all the form controls back to their original state when the HTML was drawn. For example, let's take a textbox:
<input type="text" value="Hello">
If you enter "world" into the textbox, then hit the reset button, all that's happening is that the value that's in the HTML ("Hello") is put back into the control. This is a function of the browser and has nothing to do with the viewstate. I don't know if there is any way for you to access the original value programmatically (in javascript).
Peter
------------------------------------------------------
Work smarter, not harder.
|
|
 |