Javascript client-side post and keep viewstates?

B

Bruce W.1

I need to do a post on the client side (with an html button) to another
aspx URL, while keeping the viewstates.

So I made an html button with
onClick="location.href='whatever.aspx?state=true'"

This works but I lose everything that was in my textboxes and other
controls. I think this onClick just does a Get instead of a Post.

I'm actually posting to the same page but changing the querystring in
order to make something happen in the Global.asax.cs
Application_BeginRequest method. Something that can't wait to hit the
handler code of a regular ASP.NET button. The querystring must be
changed on the client side.

So how can I post back to the same page, keep everything that was in the
controls, and change the querystring?

Thanks for your help.
 
K

Keith

location.href will do a get and not a post. Try
modifying the action attribute of the form to equal the
other ASPX page programattically. Then just call the
submit method on the form itself. That may work.
 
P

Peter Rilling

Will posting a viewstate to another page work? I thought that the viewstate
was bound to a specific page.
 
B

Bruce W.1

Keith said:
location.href will do a get and not a post. Try
modifying the action attribute of the form to equal the
other ASPX page programattically. Then just call the
submit method on the form itself. That may work.
================================================

Using an ASP.NET button I tried adding an action attribute using the URL
with the querysting. This did not work. Like this:
action="whatever.aspx?state=true"
But this did not change the requested URL, not sure why.

Found one article that touches on the matter, but doesn't really answer
my question:
http://www.codeproject.com/aspnet/jsnopostback.asp

I want to post back to the same page but with a querystring in the URL
to trigger something in Application_BeginRequest. It doesn't have to be
a querystring but I don't know what else might be detectable in
Application_BeginRequest.
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top