从C#中的文本框更改文本调用事件 [英] Call an event on text changed from textbox in C#

查看:76
本文介绍了从C#中的文本框更改文本调用事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在文本更改时调用波纹管功能。



I want to call bellow function when the text is changed.

public void text_change(object sender){
}





以下方法适用于JS功能,当我在同一页面中调用该事件时无法工作



the below method works fine for JS function and not working when I call the event in the same page as bellow

text.Attributes.Add("onchange", "text_change(text)");





如果我错过任何东西,请纠正我。或任何其他方式来达到这个要求。



请帮我解决这个问题。谢谢。



我尝试过:





Correct me if I missed anything. Or any other way to achieve this requirement.

Please help me to solve this.Thanks in Advance.

What I have tried:

text.Attributes.Add("onchange", "text_change(text)");

推荐答案

不,你没有。相信我。如果您开始在C#代码中处理文本更改事件,那么您的用户会遇到缓慢且不舒服的用户体验 - 因为他键入的每个密钥都必须执行往返服务器才能进行处理,而且速度很慢。非常慢。它还需要启动整页加载,并将整个受影响的页面重新发送回客户端。



处理文本在Javascript中更改,而不是C# - 否则你的用户界面会变得缓慢而繁琐:你的用户会去其他地方!

请记住:Javascript在客户端浏览器上本地执行 - 所有C#代码都在服务器上执行,因此它需要跨越互联网,启动服务器应用程序以加载您的页面,处理输入,生成新的页面数据,将其发送回客户端,在浏览器中呈现它,最后用户可以看到他输入的内容。你可以使用Ajax加速这种程度,但即便如此,它也不会像按键,本地处理那样快
No, you don't. Trust me on this. If you start handling text changed events in your C# code, then your user is in for a slow and uncomfortable user experience - as every key he types has to do a round trip to the server in order to be processed, and that's slow. Very slow. It also requires a full page load to be started and the whole affected page to be sent back anew to the client.

Handle text changed in your Javascript, not C# - otherwise your UI becomes slow and cumbersome: and your users will go elsewhere!
Remember: Javascript is executed locally on the Client browser - all C# code is executed at the server, so it needs a trip across the internet, fire up the server app to load your page, handle the input, generate new page data, send it back to the client, render it in the browser, and finally the user gets to see what he typed. You can accelerate this to an extent using Ajax, but even then it's not going to be as quick as "press key, handle locally"


这篇关于从C#中的文本框更改文本调用事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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