Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP ASP.NET Javascript .NET HTML , +
how to bound a TextBox value with a label in asp.net, SO that whatever be typed in the TextBox it reflects the same in same time in the label.
Posted 7-Jul-13 21:56pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can use the TextBox TextChanged Event to do that.. Text Entered in Textbox will be displayed in Label after hitting enter
 

protected void TextBox1_TextChanged(object sender, EventArgs e)
{
    Label1.Text = TextBox1.Text;
}
 

Hope that gona help...
  Permalink  
Comments
kool15th at 8-Jul-13 6:17am
   
Thanks...But it will only happen when the complete entry have been made in the textbox. I want every instant update.
Khan JI at 8-Jul-13 6:40am
   
Than You can use JavaScript for that...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

u can use javascript
 
<script type="text/javascript">
function CalculateBMI() {
            var Weight = parseFloat(document.getElementById('<%=txtWeigh %>').value);
            var Height = parseFloat(document.getElementById('<%=txtHeight %>').value);
            if (!isNaN(Weight) && !isNaN(Height)) {
                var Ms = parseFloat((Height) / 100);
                document.getElementById('<%lblBmi%>').value = parseFloat((Weight) / (Ms * Ms));
                return false;
            }
            else {
                document.getElementById('<%lblBmi%%>').value = "";
                return false;
            }
        }
 </script>;
 

these are ur textboxes to call javascript method
 
<asp:TextBox ID="txtWeight" runat="server"
                onkeyup="CheckFirstChar1(this);CalculateBMI();"
                ></asp:TextBox>
 
 <asp:TextBox ID="txtHeight" runat="server"
                onkeyup="CheckFirstChar1(this);CalculateBMI();"
                ></asp:TextBox&gt
 
Accept as answer if solve you problem.
  Permalink  
v2
Comments
kool15th at 8-Jul-13 6:44am
   
Their are some error in it which i m not getting...
The one I have corrected txtHeight textbox is not closed.
 
The error shown is:
 
Compiler Error Message: CS1002: ; expected
 
Source Error:
 

Line 302: #line default
Line 303: #line hidden
Line 304: @__w.Write("\').value = parseFloat((Weight) / (Ms * Ms));\r\n return false;\r\n " +
Line 305: "}\r\n else {\r\n document.getElementById(\'");
Line 306:
 
Source File: c:\Users\manish\AppData\Local\Temp\Temporary ASP.NET Files\root\1d4d24dc\9b25ae0e\App_Web_webform1.aspx.cdcab7d2.nenlpaot.0.cs Line: 304
kool15th at 8-Jul-13 6:45am
   
<%@ Page Title="" Language="C#" MasterPageFile="~/admin.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="masterji.WebForm1" %>
 
and it shows error in the above line too that ";is expeted"
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

<script>
        function WriteText()
        {
            var TextBox1= document.getElementById('TextBox1');
            var Label1= document.getElementById('Label1');
            Label1.innerText=TextBox1.value;
        }
    </script>
 

use this WriteText function on onkeyup="WriteText();" of textbox
 
like this
<asp:textbox id="TextBox1" onkeyup="WriteText();" runat="server" xmlns:asp="#unknown"></asp:textbox>
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

actually txtHeight is not closed if u Observe above code u can find out.
that is the Mistake
 
so pls change as like </asp:TextBox> and remove this CheckFirstChar1(this) method
 
copy this code
<asp:TextBox ID="txtWeight" runat="server"
                onkeyup="CalculateBMI();"
                ></asp:TextBox>
 
 <asp:TextBox ID="txtHeight" runat="server"
                onkeyup="CalculateBMI();"
                ></asp:TextBox>
 
Accept as answer if solve you problem.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 9 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100