Click here to Skip to main content
15,911,711 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to execute server side method to calculate sum of two textbox's values in third textbox in asp.net but I don't know how to do it.

I had tried lot of javascript but it is giving me error.

can any one tell me how to do it.

thnx in advance


I have three text box
txt_qty
txt_rate
txt_amount

I want to do
C#
txt_amount.text=txt_qty.text * txt_rate.text
Posted
Updated 5-May-13 8:14am
v2
Comments
Please post your code...
Maciej Los 5-May-13 13:32pm    
Show us code of your asp.net site. Use "Improve questtion" widget.
[no name] 5-May-13 14:22pm    
In addition to posting the code that you have written that demonstrates your problem, it would be nice to know what the error is.

C#
<asp:textbox id="txt_qty" runat="server" xmlns:asp="#unknown"></asp:textbox>

<asp:textbox id="txt_rate" runat="server" autopostback="True" ontextchanged="txt_rate_TextChanged" xmlns:asp="#unknown"></asp:textbox>

<asp:textbox id="txt_amount" runat="server" xmlns:asp="#unknown"></asp:textbox>



C#
protected void txt_rate_TextChanged(object sender, EventArgs e)
{

        /*implement your calculations here*/
        txt_amount.text=txt_qty.text * txt_rate.text;
}
 
Share this answer
 
Comments
jagdish123061 6-May-13 2:52am    
Thnx rohan leuva it worked but i want to do it without postback can u give me code in javascript
If you mean .NET event, you should understand: you cannot raise event (correct term is: invoke event) from nowhere except the class where the event instance is declared. You cannot do this even in the derived class. Why? This is one of the limitations of events, compared to the "regular" delegate, an important fool-proof feature.

As you are talking about the event already declared in the library, there is no a way to invoke it in any other way; except the case when you actually change text of the control. So what to do? As this is the fool-proof feature, apparently, a way to go is not to be one of those fool. :-) You never really need to invoke this event, but probably you simply need to have the same effect as the one caused by this event. Then do exactly this.

Develop some method you want to be called when the text is modified. Call this event in two places: in the handler of the event (and then don't do anything else in you handler) and elsewhere. Problem solved.

—SA
 
Share this answer
 

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