对textbox textchanged事件的计算 [英] Calculations on textbox textchanged event

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

问题描述

我有一个很大的形式,为用户提供了大量的计算。几乎所有控件(文本框)都是AutoPostBack。但是假设我在AutoPostBack On的文本框中输入值,页面会按原样重新加载,但是需要时间并且在输入值后光标转到另一个控件上...我在每个textbax textchanged事件上编写代码并且我上传了我的应用程序服务器需要时间来计算..

I have a very big form with lots of calculations for the user. Almost all of the controls(Textboxs) are AutoPostBack . But if suppose I enter value in textbox with AutoPostBack On, the page reloads as it should, but takes time and after entering the value the cursor goes on another control... I write code on each textbax textchanged event and i uploaded my application on server it takes time to calculation..

推荐答案

另外需要注意的是,取决于你目前正在做什么:



如果您将文本更改放回到具有文本更改事件的同一文本框中,那么在一般情况下,您将进行另一个文本更改:可能无限循环,直到您达到恒定价值。这种多次执行也会降低速度(或者完全锁定应用程序)。



解决方案,如果您现在(或将来)将更改发布回原始文本源是在处理程序中放置一个静态标志,以防止它运行两次(虽然你确实得到两次访问 - 但只有一次只重置标志并返回)。
Another thing to watch out for, depending upon what you're currently doing:

If you put your text changes back in the same text box that has the text-change event then you are, in the general case, doing another text change: a potentially endless loop until and if you reach a constant value. This multiple execution can also slow things down (or lock the application, altogether).

Solution, should you now (or in the future) be posting your changes back to the original text source is to put a static flag in the handler to prevent it from running twice (although you do get two visits - but one just resets the flag and returns).


尝试JavaScript那是最好的选择。它不仅可以固定您的过程,还可以帮助您防止往返服务器。

-SG
Try JavaScript that's the best option. It not only fasten your process but also help u to prevent the round trip to the server.
-SG


将您的控件划分为用户控件,只需将避免混淆逻辑。将相关控件放在特定的用户控件中。

接下来在每个用户控件中使用javascript放置计算逻辑,并将最终计算值放在隐藏字段中。将值作为用户控件的只读属性公开。将每个用户控件放在一个单独的UpdatePanel中,以确保整个页面不会回发,只是一个特定的UC。



你不仅可以减少回发量,您还将清理页面自己的处理并在应用程序中引入大量模块化。
1st divide your controls into user controls, just to avoid mixing up the logic. Put related controls in specific user controls.
Next put calculation logic using javascript within each user control and put the final calculated value in a hidden field. Expose the value as a readonly property from the user control. Put each user control in a separate UpdatePanel, to ensure the entire page doesn't posts back, just a specific UC only.

Not only will you be able to reduce the amount of postbacks, you will also clean up the page's own processing and introduce lots of modularity in the application.


这篇关于对textbox textchanged事件的计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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