Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Viewstate from JavaScript

Status
Not open for further replies.

jmikow

Programmer
Mar 27, 2003
114
0
0
US
Is there a way to access the Viewstate from Javascript and update it?

I'm working on trying to change the color of some controls (Textbox, DropDownList, DataGrid child controls) when the data in them is changed. I have the Javascript "onchange" method working to set the color on the client-side but when I postback the page it does not retain the color changes.

I'm trying to figure out a way that I can achieve a color change that will last through Postbacks and changing the viewstate was my latest idea.

Any suggestions welcome!

Thanks!
 
Couldn't you just change the colour in server side code (or are you wanting to avoid the postback each time the data is amended)?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
The ViewState has a built-in mechanism to prevent tampering (it's stored with a hash) for security reasons, so even if you were to decode it, parse it, manipulate it, and PostBack with it you'd get a server error by default.

You can consider storing your info in your own hidden field on the page (see Page.RegisterHiddenField and Request["fieldName"]), but the easiest way might be to duplicate the color-change logic on the server based on the TextBox values.
 
Originally I had tried the server-side code color change and it was not working properly. Sometimes it would change and others not.

I think I've figured it out and now I am able to do it with server-side code, thus eliminating the need to modify the ViewState.

Thanks for the responses!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top