如何在asp.net中引发textchange事件? [英] how to raise textchange event in asp.net?

查看:213
本文介绍了如何在asp.net中引发textchange事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行服务器端方法来计算asp.net中第三个文本框中两个文本框值的总和,但我不知道该怎么做。



我尝试了很多javascript但它给了我错误。



任何人都可以告诉我该怎么做。



thnx提前





我有三个文本框

txt_qty

txt_rate

txt_amount



我想做

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

txt_amount.text=txt_qty.text * txt_rate.text

推荐答案

<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>










protected void txt_rate_TextChanged(object sender, EventArgs e)
{

        /*implement your calculations here*/
        txt_amount.text=txt_qty.text * txt_rate.text;
}


如果你的意思是.NET事件,你应该明白:你不能从无处引发事件(正确的术语是:调用事件),除了声明事件实例的类。即使在派生类中也不能这样做。为什么?与常规代表相比,这是事件的限制之一,重要的防呆功能



因为你是谈到已在图书馆中宣布的事件,没有办法以任何其他方式调用它;除了实际更改控件文本的情况。那么该怎么办?由于这是一个傻瓜式的功能,显然,一种方法是不要成为那些傻瓜之一。 :-)你真的不需要调用这个事件,但可能你只需要具有与此事件引起的效果相同的效果。然后做到这一点。



开发一些在修改文本时要调用的方法。在两个地方调用此事件:在事件的处理程序中(然后在处理程序中不做任何其他操作)和其他地方。问题解决了。



-SA
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


这篇关于如何在asp.net中引发textchange事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆