Changing hidden values

J

Jeremy Ames

I have a form that contains two hidden values, among other controls. I was wondering, if I change these values in server script and immediately do a server.transfer, do these values get updated before the page is changed?

I want to say that because the values are changed but the page is never reloaded after the change, that these changes do not take effect before the server.transfer. Please let me know if I am correct here. I think I am finally getting the hang of asp.net.

Thanks,

Jeremy Ames
 
J

Jeffrey Palermo

When you do a Server.Transfer, the called page has access to the Querystring
and Forms collections of the original server post. The transfering page is
unloaded, so all data there will be gone. The called page is a new instance
of the new page, so you are starting a fresh Page instance.

Jeffrey Palermo


I have a form that contains two hidden values, among other controls. I was
wondering, if I change these values in server script and immediately do a
server.transfer, do these values get updated before the page is changed?

I want to say that because the values are changed but the page is never
reloaded after the change, that these changes do not take effect before the
server.transfer. Please let me know if I am correct here. I think I am
finally getting the hang of asp.net.

Thanks,

Jeremy Ames
 
K

Kevin Spencer

Hi Jeremy,

It will help if you don't think of your executable code as "script" but
objects instead. ASP.Net has 2 components in every Page: The server-side
objects, and the client-side HTML. Neither of these necessarily has much to
do with the other. It's more useful to think of them sending messages to
each other. That is, the server-side objects which generate the client-side
HTML "send messages" by changing the HTML in the page. The client-side HTML
"sends messages" by posting back to the server. Stick with me, and shortly
you'll understand why I'm putting it this way.

You say that you have "a form that contains two hidden values." However,
that form has 2 components to it: The server-side objects, and the
client-side HTML. The server-side objects can certainly create hidden form
fields in the client-side HTML. However, these client-side form fields are
not necessarily connected in any way with a server-side objects. After all,
HTML is just text. You could create a client-side hidden form field by
simply writing the appropriate HTML into your Response. If that is indeed
what you did, how will the server-side objects have any notion that you
changed their values? There are no corresponding objects on the server to
which they are wired.

When you do a Server.Transfer, you are performing a purely server-side
operation. No Response is sent to the browser, and the HTML that resided in
the browser is history. You are simply transferring the HttpContext from one
Handler (Page object) to another. Only objects in memory will be
transferred. In order to transfer some client-side form value to the new
Handler, you have to either use server-side objects (such as
HtmlInputHidden) or place the values from the Request.Form Collection that
are not linked to any server-side objects INTO a server-side object, such as
a Public field or Property of the Page object. Or, you could just put the
values directly into the HttpContext. Any in-memory server-side object that
is accessible from the HttpContext after the transfer will be fine.

I hope the long explanation will help you to further get the hang of
ASP.Net. :)

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


I have a form that contains two hidden values, among other controls. I was
wondering, if I change these values in server script and immediately do a
server.transfer, do these values get updated before the page is changed?

I want to say that because the values are changed but the page is never
reloaded after the change, that these changes do not take effect before the
server.transfer. Please let me know if I am correct here. I think I am
finally getting the hang of asp.net.

Thanks,

Jeremy Ames
 
C

Charlie@CBFC

A good way to find out is by turning on debugger and inspect values.

Charlie


I have a form that contains two hidden values, among other controls. I was
wondering, if I change these values in server script and immediately do a
server.transfer, do these values get updated before the page is changed?

I want to say that because the values are changed but the page is never
reloaded after the change, that these changes do not take effect before the
server.transfer. Please let me know if I am correct here. I think I am
finally getting the hang of asp.net.

Thanks,

Jeremy Ames
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top