1

I am new to jQuery.

I have a web service which returns some data. I assign this data to a textbox using jQuery but when I want to access this value in C#, it generates an exception incorrect format.

This is my jquery code.

$('#Ltrl_GSalary').html(GrossSalary);
 $('#Ltrl_NetSalary').html(GrossSalary-parseInt(TotalDeduction));

This code works fine, it displays data.

I also tried:

$('#Ltrl_GSalary').val(GrossSalary);
 $('#Ltrl_NetSalary').val(GrossSalary-parseInt(TotalDeduction));

This code does not display any data.

This is my C# code

 salary.NetSalary = Ltrl_NetSalary.Text.ToDecimal();
 salary.GrossSalary = Ltrl_GSalary.Text.ToDecimal();

This causes the exception incorrect format.

4
  • looks like you Ltrl_GSalary is not an input element..since html() is working.. can you post your related html code Commented May 3, 2013 at 5:32
  • Ltrl_GSalary is asp.net lable control Commented May 3, 2013 at 5:33
  • 2
    Lable is not input type control, to get the values on server side code which change using jquery you need input type control like textbox, or you can use hidden field as well. Thanks Commented May 3, 2013 at 5:35
  • hidden field fields works thanks Commented May 3, 2013 at 5:51

2 Answers 2

3

Try to use Hidden field to capture data

Sign up to request clarification or add additional context in comments.

Comments

0

You can use Convert.ToInt32 for this purpose.

It will handle format exception. And check with value in Ltrl_NetSalary.Text

Try to use:

salary.NetSalary = Convert.ToInt32(Ltrl_NetSalary.Text);
salary.GrossSalary = Convert.ToInt32(Ltrl_GSalary.Text);

hope Its Helpful.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.