How to get value hidden in C # when it is set by jquery after postback

I need jquery.how, I get the value of the hidden field after the message back to csharp. when ever a post back occurs value disappears. this is my hidden field.

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

this is jquery code where it assigns data to it after successfully executing ajax web service.

 var BasicSalary = $('Hid_BasicSalary'); BasicSalary.val(data["BasicSalary"]); 

this is code with clear code, when I click the postback button, it happens after this node data.

 protected void Btn_PIncrementSave_Click(object sender, EventArgs e) { try { TxBx_IncrementAmount.Text = Hid_BasicSalary.Value.ToString(); } catch (Exception ex) { Utility.Msg_Error(this.Master, ex.Message); } } 

Please help me

+4
source share
6 answers

In jQuery, we use a selector to select any elements, and we need to place . for class and # in id selector, so please put # or . in front of your item.

In your case, $('#Hid_BasicSalary'); or $('.Hid_BasicSalary'); - Your reply.

+3
source

I missed # s $.

 var BasicSalary = $('Hid_BasicSalary'); 

I am writing this instead

  var BasicSalary = $('#Hid_BasicSalary'); 
+2
source

try it

 var BasicSalary = $('#Hid_BasicSalary'); 
+2
source

Usage This code loads the page to get the new value from the hidden

 Request.Form["hdnvalue"]; 
+1
source

you missed the "#" and I think you should use hidden clientid control.

 var BasicSalary = $('#<%=Hid_BasicSalary.ClientID%>'); 
+1
source

try this to get server control value from javascript / jquery

 var BasicSalary = document.getElementById('<%=Hid_BasicSalary.ClientID%>').value 
0
source

Source: https://habr.com/ru/post/1479319/


All Articles