The value is not retained with Page.ClientScript.RegisterHiddenField in asp.net

1.6k Views Asked by At

In Asp.net c#, with this syntax:

 Page.ClientScript.RegisterHiddenField("hfFileName", Value);

I can define a Hiddenfield:

1) Why in this code , the value is nothing:

function pageLoad() {     
alert(document.getElementById("hfFileName").getAttribute("value")); 
}

2) Whats the difference between this hiddenField and this one which I can define from Asp.net toolbox:

<asp:HiddenField ID="HiddenField1" runat="server" />

Thank you in advanced.

It was working before, I changed some code in Update panels and now its not working, is it possible of that?

1

There are 1 best solutions below

4
Dev D On

Try the following:

on Code Behind:

protected void Page_Load(object sender, EventArgs e)
        {
            Page.ClientScript.RegisterHiddenField("hfFileName", "testvalue");
        }

on Jquery:

 $(document).ready(function () {
            alert(document.getElementById("hfFileName").getAttribute("value"));
        })

This is working for me.