4

i am nwe to jquery.how i get value of hidden field after post back in csharp. when ever post back occures value dissapear. this is my hidden field.

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

this is jquery code where is assign data to it after succsesful execution of ajax web service.

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

this is c sharp code when i click on button postback occurs afte 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

Amit
  • 15,217
  • 8
  • 46
  • 68
Amjad Shah
  • 575
  • 2
  • 6
  • 14

6 Answers6

3

In jQuery we use the selector for select any elements, and we have to put . for the class and # to the id selector so please put # or . before your element.

In your case, $('#Hid_BasicSalary'); or $('.Hid_BasicSalary'); is your answer.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Developerzzz
  • 1,123
  • 1
  • 11
  • 26
2

i was missing # with $.

var BasicSalary = $('Hid_BasicSalary');

i write this instead of this

 var BasicSalary = $('#Hid_BasicSalary');
Amjad Shah
  • 575
  • 2
  • 6
  • 14
2

Try this

var BasicSalary = $('#Hid_BasicSalary');
Nemo
  • 310
  • 1
  • 3
  • 12
1

Use This code is page load to get new value from hidden

Request.Form["hdnvalue"];
Neeraj Dubey
  • 4,401
  • 8
  • 30
  • 49
1

you missed the "#" and i think that you should use the hidden control's clientid.

var BasicSalary = $('#<%=Hid_BasicSalary.ClientID%>');
Nate
  • 91
  • 8
0

try this to get value of server control from javascript/jquery

var BasicSalary = document.getElementById('<%=Hid_BasicSalary.ClientID%>').value
Sagar Hirapara
  • 1,677
  • 13
  • 24