In this article I will explain with an example, how to display (show) TextBox value in Label using JavaScript in ASP.Net.
 
 

HTML Markup

The HTML Markup consists of following controls:
TextBox – For capturing Name.
Button – For showing TextBox value to Label.
The Button has been assigned with an OnClientClick event handler.
Label – For capturing TextBox value and showing to user.
Name:<asp:TextBox ID="txtName" runat="server" />
<asp:Button ID="btnShow" runat="server" Text="Show Name" OnClientClick="return ShowName()" />
<hr />
<asp:Label ID="lblName" runat="server"></asp:Label>
 
 

Displaying (Showing) TextBox value in Label using JavaScript in ASP.Net

When the Show Name Button is clicked, the ShowName JavaScript function is called.
Inside this function, first the TextBox and Label controls are referenced and the TextBox value is set to the Label control and the FALSE is returned.
<script type="text/javascript">
    function ShowName() {
        //Reference the TextBox.
        var txtName = document.getElementById("<%=txtName.ClientID%>");
 
        //Reference the Label.
        var lblName = document.getElementById("<%=lblName.ClientID%>");
 
        //Copy the TextBox value to Label.
        lblName.innerHTML = txtName.value;
 
        return false;
    }
</script>
 
 

Screenshot

Display (Show) TextBox value in Label using JavaScript in ASP.Net
 
 

Browser Compatibility

The above code has been tested in the following browsers.
Microsoft Edge   FireFox  Chrome  Safari  Opera
* All browser logos displayed above are property of their respective owners.
 
 

Demo

 
 

Downloads