如何使用C#来获得Web表单的文本框的GotFocus,LostFocus事件 [英] How to get GotFocus, LostFocus event of a textbox in Webforms using C#

查看:190
本文介绍了如何使用C#来获得Web表单的文本框的GotFocus,LostFocus事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能够在创建一个网站,以获取事件GotFocus,引发LostFocus一个文本框。我只是想。正如我刚才在我的问题问及如何得到一个文本框的值到另一个文本框时,焦点文本中的WinForms其他文本框。我能够工作,它的窗口的形式完成的。但是,当我尝试同样的一个网站,我不能让这些事件的.....如果Java脚本的使用得到这些事件? Pelase帮助

I am not able to get the event GotFocus, LostFocus of a textbox while creating a website. I just wanted. As I have asked earlier in my question how to get the value of one textbox into another textbox when focus is text to the other textbox in winforms. I was able to work it done in windows form. But, when I try the same in a website, I am not able to get these events their.....Should Java script be used to get these events? Pelase help

推荐答案

的GotFocus,引发LostFocus事件文本框在Windows控制但器WebControls,你不会得到这些,而不是你应该尝试客户方脚本(JavaScript)的。

GotFocus, LostFocus events for TextBox are in Windows Control but for WebControls, You will not get these, Instead of you should try clientside scripting (Javascript).

在JavaScript的你会得到事件聚焦和模糊的文本框(这实际上是一种输入类型网页=文本),你可以使用这些为你的目的。

In javascript you will get the event focus and blur for a textbox (which is actually a input type="text" on web page) , and you can use these for your purpose.

有关设置事件处理程序,使用上+事件作为事件处理程序,并提供JS code要执行。

For setting an event handler, use on + event as event handler and provide the js code which to execute.

像模糊的情况下,您应该添加属性的onblur 和重点添加属性的onfocus

like for blur event you should add attribute onblur and for focus add attribute onfocus

在Javascript中你可以试试,如果你的aspx有文本框为

In Javascript you can try, if your aspx has TextBox as

<asp:TextBox runat="server" id="textbox1" onblur="SetTextInTextBox2()" />
<asp:TextBox runat="server" id="textbox2" onfocus="SetTextInTextBox2()" />

在JavaScript

in javascript

function SetTextInTextBox2()
{
    document.getElementById('textbox2').value = document.getElementById('textbox1').value;
}

这篇关于如何使用C#来获得Web表单的文本框的GotFocus,LostFocus事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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