Reputation: 595
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
.
Upvotes: 1
Views: 387
Reputation: 9074
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.
Upvotes: 0