0

How set a new value for HiddenField in java script. My Hidden field and button is like this:

<asp:HiddenField Id="tz" runat="server" Visible ="false"/>
<asp:Button ID="BTN_Export" runat="server" Text="Export to *.xlsx" onClientClick="SetValue();"/>

And my java script:

<script type="text/javascript">
        function SetValue() {
            document.getElementById('tz').value = "testing !!!!!";
        }
    </script>

When i try to pun a new value to HiddenField get me error:

enter image description here

Omore
  • 614
  • 6
  • 18
Vladut
  • 647
  • 1
  • 10
  • 35

1 Answers1

1

Use client id of hidden field, when asp.net control is rendered its id is slightly changed. or you can get client id in JS using regex or as:

document.getElementById('<%= tz.ClientID %>').value

OR

Get asp.net control with partial id

Community
  • 1
  • 1