0

how to use javascirpt for client side to transfter the values suppose when i enter 2 in textbox1 then in thextbox2 it should show 4 how is it possible because there is no keypress event is there in asp.net texbox control please help

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by jamshed ahmed
0

>there is no keypress event is there in asp.net texbox control

That's true. There is no keypress event with ASP.NET controls but you can attach/add javascript code with ASP.NET controls.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript">
        function doSomething() {
            var t1, t2;
            t1 = document.getElementById("TextBox1");
            t2 = document.getElementById("TextBox2");

            no = parseInt(t1.value);
            no = no * 2;

            t2.value = no;
        }
        
    </script>
</head>
<body>
    <form id="form1" runat="server" onsubmit="return ValidateForm()">
    <asp:TextBox ID="TextBox1" onkeyup="doSomething()" runat="server"></asp:TextBox>
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    </form>
</body>
</html>
0
aspx form coding 
<script language="javascript" type="text/javascript" >
    
    function GetKeyPress()
    {
    document.getElementById('<%=TextBox2.ClientID%>').value=document.getElementById('<%=TextBox1.ClientID%>').value*2
    }
    </script>    
     
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox2" runat ="server" ></asp:TextBox>
        <asp:TextBox ID="TextBox1" onkeyup="GetKeyPress();" runat="server"></asp:TextBox>
    
and that is aspx.cs form coding

protected void Page_Load(object sender, EventArgs e)
    {
        TextBox1.Attributes.Add("onkeyup", "GetKeyPress()");
        
    }

BUT WHY WE ARE USING THIS CODE >>>>TextBox1.Attributes.Add("onkeyup", "GetKeyPress()"); any help more just in few lines thx

>there is no keypress event is there in asp.net texbox control

That's true. There is no keypress event with ASP.NET controls but you can attach/add javascript code with ASP.NET controls.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript">
        function doSomething() {
            var t1, t2;
            t1 = document.getElementById("TextBox1");
            t2 = document.getElementById("TextBox2");

            no = parseInt(t1.value);
            no = no * 2;

            t2.value = no;
        }
        
    </script>
</head>
<body>
    <form id="form1" runat="server" onsubmit="return ValidateForm()">
    <asp:TextBox ID="TextBox1" onkeyup="doSomething()" runat="server"></asp:TextBox>
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    </form>
</body>
</html>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.