Tuesday 14 May 2013

How to bind TextBox with Label in asp.net using jquery.

Introduction:-


Bind TextBox with label in asp.net using c#  means while you are writing inside textbox at the same time data will show on label. For this i have used jquery function.

Design Page:-

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BindTextBoxWithLabel.aspx.cs" Inherits="BindTextBoxWithLabel" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
    $(function(){
    $("input[type=text]").keypress(function(){
    var lbl=document.getElementById("Label1");
    var text=document.getElementById('<%=TextBox1.ClientID%>').value;
    lbl.innerHTML=text;
    });
    });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       Write Something In Textbox : <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
        See the result in label at same time :<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>


Run the code and see the Output.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.