我现在有一个页面,有两个TextBox框体 和 一个Button1
TextBox1 为可编辑,TextBox2只读。要实现的功能:1、当我在TextBox1输入值的时候,TextBox2会自动将TextBox1的值一个一个的输入。
(例如:TextBox1输入一个“A”,TextBox2也出现“A”;当TextBox1再输入第二个字符“B”,TextBox2立刻出现“B”)2、传值完成后,按Button1后,TextBox1和TextBox2把自己的值保存到数据库中。
希望各位大侠,直接把成功的代码发出来,我研究研究。谢谢!

解决方案 »

  1.   

    客户端 用onchange事件啊。直接赋值就可以了啊
      

  2.   

    用JS,onkeyup或者onkeypress事件
    懒的写了,楼下写吧
      

  3.   

     <script>
    function SetValue()
    {
    document.getElementById("TextBox2").value=document.getElementById("TextBox1").value;
    }
     </script>
    <asp:TextBox ID="TextBox1" runat="server" onkeyup="SetValue()"></asp:TextBox>
    <asp:TextBox ID="TextBox2" runat="server" ReadOnly></asp:TextBox>
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />        protected void Button1_Click(object sender, EventArgs e)
            {
                Response.Write(TextBox1.Text);
                Response.Write(TextBox2.Text);//如果TextBox2有了ReadOnly属性,这里就获取不到值,要获取到值,必须在html中把ReadOnly去掉。
            }
      

  4.   

    忘记说我的平台了, 小弟用VS2005  VB .NET
      

  5.   

    其实要获取到有ReadOly属性的TextBox值,需要在TextBox旁边放一个HiddenField,在js中同时将value赋予HiddenField,然后在button的后台事件中获取HiddenField的value添加:<asp:HiddenField ID="HiddenField1" runat="server" />
    js修改:
    function SetValue()
    {
    document.getElementById("TextBox2").value=document.getElementById("TextBox1").value;
    document.getElementById("HiddenField1").value=document.getElementById("TextBox1").value;
    }
      

  6.   

    <asp:TextBox ID="TextBox1" runat="server" onblur="A(this.Value)"></asp:TextBox>
    <asp:TextBox ID="TextBox2" runat="server" ReadOnly></asp:TextBox>function A(s)
    {
    document.getElementById("TextBox2").value=s;
    }
      

  7.   

    你是说传值的时候,是隐藏的框体“HiddenField”的值 保存到数据库吗?
      

  8.   

    第一个问题:
    <asp:TextBox ID="TextBox1" runat="server" onkeyup="document.getElementById('TextBox2').value = document.getElementById('TextBox1').value;">
    </asp:TextBox><asp:TextBox ID="TextBox2" runat="server" ReadOnly="True"></asp:TextBox>
      

  9.   

    而TextBox2只供显示给用户看,对吗?
      

  10.   

    Button 后台事件怎样写呢?不好意思,小弟不太懂。
      

  11.   

    onkeyup="SetValue()"onblur="A(this.Value)"刚才按照你们说的来做,没有成功。
    这两个事件  在我的页面中没有,是什么原因啊。晕了~
      

  12.   

    我复制了,还是不行哦!当我在页面上的TextBox1输入值,TextBox2并没有显示值,没有任何反映
      

  13.   

    而且你的脚本我输入后,其中的“Value”也没有<script>
                function SetValue()
                {
                    document.getElementById("PartSpecField").value = document.getElementById("PartNameField").value
                }
            </script>
      

  14.   


    把你的html代码贴出来,我看看你复制的样子。
      

  15.   

    onchange 和onblur都是失去焦点的时候触发,建议使用onpropertychange事件
    代码如下: <asp:TextBox ID="TextBox1" runat="server" onpropertychange="SetTb2Value()"></asp:TextBox>
            <asp:TextBox ID="TextBox2" runat="server" ReadOnly=true></asp:TextBox>
            <script type="text/javascript">
            function SetTb2Value()
            {
                document.getElementById('<%=TextBox2.ClientID%>').value=document.getElementById('<%=TextBox1.ClientID%>').value;
            }
            </script>
      

  16.   

    Button1保存事件里这样写,我这是直接存字符的,建议你用参数形式传(其余的我懒的写了)dim tbText1 as string=Me.TextBox1.Text;
    dim tbText2 as string=Me.TextBox2.Text;dim strSQL as string="insert into table(value1,value2)values('"& tbText1  &"','"& tbText2 &"')"
      

  17.   

    客户端的Onchange事件
    用js写
      

  18.   

    TextBox2.text = TextBox1.text;
    Button1.click 
      

  19.   

    我的HTML代码<script language="javascript" type="text/javascript">
                function SetValue()
                {
                    document.getElementById("PartSpecField").value = document.getElementById("PartNameField").value
                }
            </script><fb:TextBox ID="PartNameField" runat="server" OnKeyUp="SetValue()" 
                    ReadOnly="false" Style="z-index: 112; left: 211px; position: absolute; top: 197px" />
                <fb:TextBox ID="PartSpecField" runat="server" 
                    ReadOnly="true" Style="z-index: 114; left: 419px; position: absolute; top: 197px" />
      

  20.   

    textbox2.text=text1.text;
    不就ok 了嚒?
      

  21.   


    你这是<fb:TextBox,不是<asp:TextBox和input的text
      

  22.   

    这个就挺好,VB看着也能自己写出来,LZ想直接COPY?
      

  23.   

    不是直接COPY  ,是想VB .NET写出来的。我研究研究.
      

  24.   

    js中写入代码让1中输入2中得到。
    要在后台得到textbox中的值,用request.form["textbox的name"]
      

  25.   

    请问大家,如果不是<asp:TextBox>和<input的text>    的TextBox 就不能用“OnKeyUp”“OnKeyPress” 的事件。因为我的是<fb:TextBox >的