Martin Ongtangco
Martin Ongtangco

Reputation: 23505

how to fill asp.net hidden field with Jquery

im trying this format:

$("#<%= hfWidth.UniqueID %>").val($("#drag").attr("offsetWidth"));

to fill the hidden field with client-side values

but when I do postback, the values doesn't seem to be saved.

help

Upvotes: 0

Views: 21214

Answers (3)

bluwater2001
bluwater2001

Reputation: 7959

in your aspx page:

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

in your Javascript:

           function somefunction() {

                $("#<%= hdn_checkbox.ClientID %>").val("test");

            }

            $('.btnGreen').click(function () {

                somefunction();
                alert($("#<%= hdn_checkbox.ClientID %>").val());
                return true;
            });

Upvotes: 0

Martin Ongtangco
Martin Ongtangco

Reputation: 23505

fixed it with <%= hfWidth.ClientID %>

Upvotes: 3

Tarik
Tarik

Reputation: 81711

If you want to get params from the server side, you should use name instead of id attribute.

And your code should work :

$("#elementId").val("value");

Upvotes: 3

Related Questions