Get the Value of an asp:HiddenField using jQuery

后端 未结 8 2301
慢半拍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:03

    Try any of the following

    1. If ASP.Net control and javascript both are on same page, then use

      var hv = $("#"+ '<%= hidClientField.ClientID %>').val();
      
    2. If you want to access the control from some JS file, then

      // 'id$' will cause jQuery to search control whose ID ends with 'hidClientField'
      var hv = $('input[id$=hidClientField]').val();
      
    3. You can use class name selector to achieve same. Check out this similar question.

    In asp.net, controls id is mangled. Because of this your code is not working.

    Hope this works for you.

提交回复
热议问题