文本框事件和属性 [英] textbox events and properties

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

问题描述

不使用任何控件,例如窗体,按钮,我需要将textbox1的值更改为textbox2,即,如果将值输入到textbox1,则它会自动移至textbox2

without usind any controls like form ,button i need to textbox1 value to textbox2 i.e, if enter value to textbox1 it automatically move to textbox2

推荐答案

使用TextChanged事件.在textbox1的文本更改事件中,将textbox2的文本设置为textbox1的文本.参见 [
Use the TextChanged event. Set textbox2''s text to textbox1''s text in textbox1''s text changed event. See this[^] example as well.


使用以下任一事件:
Control.TextChanged事件 [ Control.LostFocus事件 [ MSDN [
Use any one of the events:
Control.TextChanged Event[^]
Control.LostFocus Event[^]


You can choose any other event too. About all the events of textbox: MSDN[^]


您有两个文本框
Textbox1
Textbox2

启用Textbox1和Textbox2的AutoPostBack ="True"

设计视图看起来像

you have a two text box
Textbox1
Textbox2

Enable Textbox1 and Textbox2''s AutoPostBack="True"

The design view is look like

<pre lang="xml"><form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"
            ontextchanged="TextBox1_TextChanged"></asp:TextBox>
        <asp:textbox ID="Textbox2" runat="server" AutoPostBack="True"></asp:textbox>
    </div>
    </form>





在VS或
中的设计视图中单击textbox1即可
在代码视图中写下以下语句





Dobble click on textbox1 in design view in VS or

write down following statement in code view

<pre lang="cs">protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        Textbox2.Text = TextBox1.Text;
    }





==>>它表明,当更改Textbox1的文本时,textbox1将刷新页面并将值放入Textbox2.

在运行时,不要忘记在Textbox1中输入值后按下Tab键





==>>It show that when Textbox1''s text is change than textbox1 will refresh the page and Put value in Textbox2.

While running don''t forgot to press Tab button after entering value in Textbox1


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

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