Pages

Thursday 13 February 2014

How to Get Asp.net Textbox Value OR Get Asp.net Label Value Using JavaScript

How to Get Asp.net Textbox Value OR Get Asp.net Label Value Using JavaScript
 


Get label value
 var amount = document.getElementById("<%=lblAmount.ClientID %>").innerHTML
Get label value
 var name = document.getElementById("<%=txtUserName.ClientID %>").value;





<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"><title>Get Asp.net Textbox Value in JavaScript</title>
    <script type="text/javascript"> function getvalues() { var name = document.getElementById("<%=txtUserName.ClientID %>").value; var amount = document.getElementById("<%=lblAmount.ClientID %>").innerHTML; alert("Textbox Value: " + name + "\n" + "Label Value: " + amount); return false } </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>UserName:<asp:textbox id="txtUserName" runat="server" /><br />
            Amount:<asp:label id="lblAmount" runat="server" text="10000" /><br />
            <asp:button id="btnValidate" runat="server" text="Get Values" onclientclick="javascript:getvalues();" />
        </div>
    </form>
</body>
</html>







UserName
Amount




Download


No comments:

Post a Comment