0

I'm working on an asp.net web app. One of my web page received a posted value from a remote server: HiddenField1.Value = Request.Form.Get("something")

And further on I'm using javascript to manipulate value from this HiddenField1.

The weird thing's that if I clicked on the "reload this page" icon on any browser: reload page icon

page's reloaded and HiddenField's value's there

However if I moved mouse to the address area and clicked on the url, address area examplethe url string's background turned blue and I hit Enter key,looked like the page's behavior's exactly the same: reloaded. However, the HiddenField's value's gone.

Any hint what's the difference between the two scenario?

Vivianne
  • 3
  • 1

1 Answers1

0

This is not strictly related to ASP.Net: it is actually a common browser behavior and you would experience the same with a different server language (php, python or whatever).

In your second scenario, the browser will send a new (GET) request to the server, asking for the last loaded URL. It would be the same if you just type the address starting from a blank Address area.

In the first case instead, you are telling your browser "please, repeat the last request you made". Maybe it was a POST request sending data (form fields) to the server, and the server did answer to the previous request inserting the hidden field you are noticing.

To recap, the second scenario is "send a GET request for this address, ignore everything else". The first is "Repeat the last request you send. If it was a POST request with form data, send it again as the time before"

Very likely in your case, the server code inserts the hidden field just in case of a particular POST request (possibly according to posted data), and not for a GET request

If you don't know the difference between POST and GET for an HTTP request, this answer can be helpful

Gian Paolo
  • 3,802
  • 4
  • 13
  • 29
  • so per your explanation, I guess in the second scenario, HiddenField get's nothing. is there some solution for this? I mean prior to page reload a variable catches the HiddenField value to be used when HiddenField's empty in future? – Vivianne May 16 '18 at 19:44
  • Just realized that I had inverted first and second scenario. I edited the answer now – Gian Paolo May 16 '18 at 20:11
  • @Vivianne, To answer to your comment, it really depends on your needs, but it seems you can write an read a cookie to get what you want. – Gian Paolo May 16 '18 at 20:13
  • i see, I just used chrome inspection, and saw in first scenario, the post's normally on, and in second scenario, there's only get request – Vivianne May 16 '18 at 20:20
  • what I need is that in the second scenario, the value from HiddenField1 (when the page's loaded correctly catching the posted value) can be somehow picked to make second scenario still work – Vivianne May 16 '18 at 20:26
  • so you can try with a cookie: write it instead of the hidden field, and later read it instead of reading the hidden field – Gian Paolo May 16 '18 at 20:44