Asp .net hidden field can't set value with jquery

后端 未结 3 806
挽巷
挽巷 2021-01-11 18:10

I can\'t set the value of a hidden field with jquery in asp .net.

My hidden field is declared like this:



        
相关标签:
3条回答
  • 2021-01-11 18:30

    Set ClientIDMode="Static" and then you can use $('#hdnSelectedTicket').val(ticketID); to set the value in asp hidden field

    like

    asp:HiddenField ID="hdnSelectedTicket" runat="server" ClientIDMode="Static"
    

    and

    $('#hdnSelectedTicket').val(ticketID);
    
    0 讨论(0)
  • 2021-01-11 18:34

    It turns out that I was putting the hidden field inside a div that was used as a model for jquery dialog. When I removed the hidden field from the div and place it somewhere else it worked.

    0 讨论(0)
  • 2021-01-11 18:55

    Depending when you are reading the value on the server side, it might not be updated on the control yet - essentially if you are doing it in a change event handler, and the control that raises the change event gets updated before the hidden control, then calling hdnSelectedTicket.Value can still return the old value.

    The easiest way to get around this issue is to cheat and get it straight from the Form collection:

    var ticketId = Request.Form[hdnSelectedTicket.UniqueID];
    
    0 讨论(0)
提交回复
热议问题