Issue concerning hidden fields

Issue concerning hidden fields

I have asked this same basic question before several times on other forums but not here.  I hope someone here can help me solve this issue:

  1. I have a strongly-typed view with a hidden field on it.
  2. When the view renders server-side, I am setting the value of the hidden field to a property of the model.
  3. When the view renders client-side, I want to get the value of the hidden field (that was set during the server-side render) and display it in a java script alert box.

This should be a simple thing to do and yet I am unable to make it work. I have set a break-point in the view and I can see that the hidden field is being set to the correct value. But the javascript will not display that value.

The page/view being rendering has been gone to before. At the time I want to display this alert, I am going back to that page and now I want to see the alert.

It is as if the page is being cached, so instead of using the new value for the hidden field it is using the old value (from the first time the page was visited). If the DOM is being cached, how I can prevent that so that each time I visit the page I get the updated values of the page and not the cached ones? What am I doing wrong??
 
  1. @<input type="hidden" id="hdnShowMsg" value="@Model.ShowMsg" />
  2. <script>
  3. alert($('#hdnShowMsg').val());
  4. </script>
 
Yes I have tried putting the javascript in the jquery pageinit event (and in every other applicable jquery event I could think of) and still get the same results.
 
Yes I have the web browser configured not to cache.
 
I am relatively new to jQuery and ASP.Net MVC but I do not see what I am doing wrong here.  No one has been able to give me any useful feedback on this. This should be a very simple thing to do but I need help with it.