Are you doing a postback to perform these calculations?
Do you need to do these calculations on the server? If not, then javascript would be a much better choice here. But if you must do the calculations on the server then you should use a PageMethod.
A PageMethod is like calling a webservice from javascript, but the method resides in your code-behind, you can call it from javascript, and no postback occurs.
To create a PageMethod there are a few things you must do.
1. Set EnablePageMethods="True" in your ScriptManager
2. Create a public static method in your code behind with the attribute [System.Web.Services.WebMethod() ]
3. The return value of this method can be of any type, but in your case should use a string to return to the textbox.
4. In your javascript create 3 functions:
function CallYourPageMethod(c) { // c is optional, but it will allow you to pass a reference to your control into the function
PageMethods.NameOfPublicStaticMethod(parameter1, parameters2, ... parameterN, onSuccessCallBack, onFailureCallBack, userContext);
}
function onSuccessCallBack(result, userContext) {
if (result) {
$get(userContext.id).innerText = result;
}
else {
alert("An unexpected error occurred");
}
}
function onFailureCallBack(error, userContext) {
if (error) {
alert("The control " + userContext.id + " caused the following error:\n" + error.get_message());
}
else {
alert("An unexpected error occurred");
}
}
A bit more detail about the code above will help too. (No idea why this turned blue).
The following call: PageMethods.NameOfPublicStaticMethod(parameter1, parameters2, ... parameterN, onSuccessCallBack, onFailureCallBack, userContext);
takes several parameters. The first N parameters must match the parameters of your code-behind method. In your case you may only require to the text of the textbox, so you'll just have one parameter here. Then following those parameters are 2 callback methods. These will handle the response from the server (success and failure) then you can pass in an optional userContext (in your case I'd pass in a reference to your control, or at the least it's ID)
In the following functions you specify what your callbacks will do. Each callback takes 2 parameters (3 actually, but you don't need the 3rd one).
Anyways, I'm sure you'll have questions, but play around with this. PageMethods are pretty frickin amazing.
Read more: http://asp.net/AJAX/Documentation/Live/tutorials/ExposingWebServicesToAJAXTutorial.aspx -- Check out the bottom of the page "Calling Static Methods In An ASP.NET Web Page"
Calling PageMethods is just like calling WebServices from javascript. Only you don't have to configure a webservice.
Good luck!
Don't forget to click "Mark as Answer" if someone answers your question. Feel free to mark more than one answer, if you feel so inclined.