ViewState and Javascript.

K

Ken Varn

Is it possible to interact with the ASP.NET ViewState using JavaScript? I
would like to be able to access data in ViewState through JavaScript and
also set ViewState data. Not sure if this is the "best:" way to send data
between ASP.NET pages and JavaScript. If anyone has other suggestions,
please feel free to comment.

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
 
M

Marina

ViewState is encrypted, so I don't think you would really be able to
retrieve data from it.
You can write out javascript that has your client side variables from the
server, to get those values over.
 
G

Guest

Hi, Ken

The simplest way is to define the variale as a hidden field runat server
<input type="hidden" runat="server" id="hidValue"/
Then you can access the value both in JavaScript and Code Behind

Bin Song, MC

----- Ken Varn wrote: ----

Is it possible to interact with the ASP.NET ViewState using JavaScript?
would like to be able to access data in ViewState through JavaScript an
also set ViewState data. Not sure if this is the "best:" way to send dat
between ASP.NET pages and JavaScript. If anyone has other suggestions
please feel free to comment

--
----------------------------------
Ken Var
Senior Software Enginee
Diebold Inc

EmailID = varn
Domain = Diebold.co
----------------------------------
 
S

Scott Allen

You could interact with ViewState, but I'd advise against doing so.

The ViewState holds data about the page and the page's controls for
use by the server, it's not designed as a communication mechanism
between client and server (in fact, ViewState is MAC encoded by
default to prevent tampering by the client).

You can certainly create your own hidden fields however and use them
to pass values back and forth, i.e:

<INPUT id="myfield" type="hidden" value="blah" runat="server">

which from the code behind will be of type
System.Web.UI.HtmlControls.HtmlInputHidden.

HTH,
 
R

Raymond Lewallen

Ken,

I believe ViewState information is Base64 encoded, so as long as you can
decode it in JavaScript, you shouldn't have a problem accessing the
decrypted form element information, although I've never tried it.

HTH,

Raymond Lewallen
 
K

Kevin Spencer

It is also compressed.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Raymond Lewallen said:
Ken,

I believe ViewState information is Base64 encoded, so as long as you can
decode it in JavaScript, you shouldn't have a problem accessing the
decrypted form element information, although I've never tried it.

HTH,

Raymond Lewallen
 
Joined
Apr 12, 2008
Messages
3
Reaction score
0
setting it to blank

I have been toying w/ the idea of setting viewstate to <blank>

I have an page /w an form and want to do jquery.ajaxform
The viewstate is just extra baggage for the network to handle...
Ive played around a bit and not had success. I assume i could set it anytime after the the form is added to the page and before the form gets submitted.

I can set it. I test it w/ an alert and it seems to eb blank. but it still shows up when i do the submit.

Has anyone tried this?

If i actually got it to work, would .net choke on the recieving end w/ an invalid MAC type error?

greg
 
Joined
Mar 15, 2010
Messages
1
Reaction score
0
Remove ViewState from page

You should use EnableViewState="false" in page attributes declaration.
gamcfarlane said:
I have been toying w/ the idea of setting viewstate to <blank>

I have an page /w an form and want to do jquery.ajaxform
The viewstate is just extra baggage for the network to handle...
Ive played around a bit and not had success. I assume i could set it anytime after the the form is added to the page and before the form gets submitted.

I can set it. I test it w/ an alert and it seems to eb blank. but it still shows up when i do the submit.

Has anyone tried this?

If i actually got it to work, would .net choke on the recieving end w/ an invalid MAC type error?

greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top