Click here to Skip to main content
15,905,874 members
Please Sign up or sign in to vote.
3.70/5 (3 votes)
See more:
hi,

I have three textboxes, here when i change the value of the text box it will calculate(multiply) the value and give output in another textbox.

My problem is...

When i change value in text 2, The appropriate values are calculated and gives in text 3.But while i retrieve text 3 value from server side it remains the older value not newer value which i changed through text 2(generated from JAVASCRIPT).

My Script is...

C#
function GetTotalamt(vat, assess, dis, dischk, net)
 {
 var V = parseFloat(document.getElementById(assess).value) * (parseFloat(document.getElementById(vat).value) / 100);

 var afterV = parseFloat(document.getElementById(assess).value) + parseFloat(V);

 var D = parseFloat(document.getElementById(dis).value);

 document.getElementById(net).value = parseFloat(afterV) - parseFloat(D);

}
Posted

Hi,

try this

document.getElementById('<%= txtFName.ClientID %>').value


where txtFname is asp.net server control
 
Share this answer
 
Comments
J.Karthick 11-Jul-11 8:15am    
:( No luck....
J.Karthick 11-Jul-11 8:48am    
Its added the values to my text....but i cant retrieve those newly added text
Syed Salman Raza Zaidi 11-Jul-11 9:17am    
for newly added text you can use a variable and store value in it
You only changed the value in the textbox on the client side (javascript). The server won't get an update on this automatically because it would otherwise always happen, even if you don't want/need it. You need to submit the form with that textbox to post those values to the server. The server code (c#) can then store those values or do whatever with it you like.

You might want to consider storing only the value of text 2 server side and recalculate the value of text 3. It's not often a good idea to store calculated values because as it implies, they can be recalculated easily most of the time.

Good luck!
 
Share this answer
 
Comments
J.Karthick 11-Jul-11 8:03am    
Ya...Thanks for your suggestion
Ankur\m/ 11-Jul-11 8:19am    
answer worth a 5!
J.Karthick 11-Jul-11 8:46am    
How can i submit it runtime?
E.F. Nijboer 13-Jul-11 15:19pm    
Ah, I see you already found that a form submit is needed. That was exactly what I meant :-)
string value = Request.Form[[TextBoxID].UniqueID]

The above works for me.
 
Share this answer
 
I found a solution....

I should POSTBACK my page to save the Client side values....
If i POSTBACK once it will automatically updated to my Server side controls...



or


You can use <asp:HiddenField> to retrieve values...

refer


http://stackoverflow.com/questions/4396804/access-server-side-variable-on-client-side-and-vice-versa-asp-net-and-javascript[^]


Thanks for your support....
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900