Hidden field value set in Javascript persists even after page refresh.

I have a very strange problem. I have hidden fields as shown below.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
        <script src="http://code.jquery.com/jquery-1.9.0.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:HiddenField ID="hid_test" ClientIDMode="Static" runat='server' />
    </div>
    </form>
<script language="javascript" type="text/javascript">
    $(function () {
        alert($('#hid_test').val());
    });
</script>    
</body>

</html>

      

And on the server side, set the value for the hidden field as follows

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then
        hid_test.Value = "abcd"
    End If
End Sub

      

Very simple code. So on the first run, the warning is shown as "abcd" as I am setting it from the server side. Good good.

Then what I did was I change the value of the hidden field using jquery from the console as shown below.

$('#hid_test').val('12');

      

After this change, when I press F5 (page reload) it is obvious that my code is server side and the value of the hidden fields should be changed to abcd

But when the page loads the alert says 12 . Means that it retains the value set on the client side. Any help is helpful. Testing in Firefox.

I disabled the FF form fill function as follows enter image description here

+3


source to share


1 answer


Firefox automatically fills in forms with the previous defaults. If you disable this feature, you must stop this behavior. This question and its answers don't seem to offer an easy way to tell Firefox not to do it in HTML; instead, the answers there focus on using JavaScript on load / unload to set field values ​​(for example, on load to overwrite what Firefox loaded automatically, on unload to encourage Firefox to remember the values ​​the page author wants to remember).



+3


source







All Articles