使用文本框自动计算 [英] Auto calculation using textboxes

查看:100
本文介绍了使用文本框自动计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在这里遇到问题,如您所见,我已经创建了3个文本框.当我在第一个和第二个文本框上输入数字时,我希望自动计算第三个文本框,这意味着没有按钮.请帮忙.我试过了,但是什么也没发生
这是我的代码:

 受保护的  TF_TextChanged( ByVal 发​​件人 As  对象 ByVal  e  As  System.EventArgs)句柄 TF.TextChanged
如果 IsNumeric(Fattend.Text) AndAlso  IsNumeric(FHour.Text) CInt (Fattend.Text)*  CInt (Fhour.Text)
结束 如果 

解决方案

是的,您可以这样做.将textbox2的属性设置为Autopostback = true,并在textbox2上创建一个TextChanged事件,并将结果存储到textbox3中.
但是,您可以使用Javascript和JQuery进行同样的操作而没有任何回发.


您无法在ASP.NET服务器端实现此功能,因为仅当发生回发时才会触发该事件.您可以通过使用客户端代码来解决此问题,这意味着您需要使用JavaScript或VBScript.

希望您能理解我的意思.


也许您真正想处理的是Fattend和Fhour TextChnaged事件,而不是结果TextBox被更改了?


Hi guys,

I got a problem here as you see i have created 3 textbox. When i input numbers on the first and second textbox i want the 3rd text box be automatically calculated meaning there is no button. Please help. I tried it but nothing happens
Here is my code:

 Protected Sub TF_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TF.TextChanged
If IsNumeric(Fattend.Text) AndAlso IsNumeric(FHour.Text) Then

    TF.Text = CInt(Fattend.Text) * CInt(Fhour.Text)
End If

解决方案

yes you can do that. Set textbox2''s property to Autopostback = true and create an TextChangedevent on textbox2 and store the result into textbox3.

But the same thing you can do with Javascript and JQuery without any postback.


You cannot achieve this in ASP.NET server side as the event will be fired only when postback occurs. You can solve this by using client side code, which means you need to use JavaScript or VBScript.

I hope you get my point.


Perhaps what you actually want to handle is the Fattend and Fhour TextChnaged events, instead of your result TextBox changed?


这篇关于使用文本框自动计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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