Get the Value of an asp:HiddenField using jQuery

后端 未结 8 2288
慢半拍i
慢半拍i 2020-12-15 16:36

I have two pages. From the first page, I open a modal with a querystring that holds that value of a client name. I then use this to set a hiddenfield on the modal that opene

8条回答
  •  执念已碎
    2020-12-15 17:01

    Because jQuery knows nothing about asp:HiddenField. It looks in the HTML structure where you have . So there's no input with ID= HiddenFieldServerDateTime. There are a few ways to overcome this:

    • Use a css selector:

      
      

      with the following selector: var serverDateTime = $(".SomeStyle").val();

      CssClass is not an available class on the HiddenField class (and it doesn't have an Attributes collection, so you can't add it manually).

    • Use ClientID property:

      var serverDateTime = $("#<%= HiddenFieldServerDateTime.ClientID %>").val();
      
    • Wrap the hidden field in something you can select:

       

      var serverDateTime = $('.date-time-wrap input[type=hidden]').val();
      

提交回复
热议问题