简体   繁体   中英

C# HiddenField value not passing

I am setting my hidden field value using jquery like this

select: function (event, ui) {
    $("#<%=hfPatientId.ClientID %>").val(ui.item.val);
}

and i want to store this value in one of my property. in my code behind i did it like this. 左侧为空右侧的值

objTicketBO.Patient_Id = hfPatientId.Value.ToString();

now my problem is my selected value is binding in right side of = but it is not binding on left side. ie on hovering over .Value i am getting the value. but on running this code it is throwing error NullValueValidation.

Problem: Your code

 select: function (event, ui) {
           $("#<%=hfPatientId.ClientID %>").val(ui.item.val);
        }

can't work, because you are try to select ASP element naming in jQuery, where are final HTML elements.

Solution: Supposing ASP will produce that element as

 <input type="hidden" name="ClientID" id="ClientID" value="225">

so jQuery function you are seeking for is

 select: function (event, ui) {
           $("#ClientID").val(ui.item.val);
        }

If ID of that hidden element is not ClientID , change jQuery selector accordingly.

thx everyone i found an problem...

i did some changes in my property..

before:-

  public string Patient_Id
    {
       get { return _patient_id; }
       set { _patient_id = Patient_ID; }
    }

Updated:-

  public string Patient_Id
   {
       get { return _patient_id; }
       set { _patient_id = value; }
   }

it's working fine now. Thanks again

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM