Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

JavaScript Get Asp.net Textbox Value | Get Asp.net Label Value in JavaScript

Oct 4, 2013
Introduction

Here I will explain how to get asp.net textbox in JavaScript or get asp.net label value in JavaScript or get asp.net control values textbox, label etc in JavaScript.

Description:

In previous articles I explained jQuery display testimonials with CSS example, jQuery get or access session value, jQuery right click context menu example, jQuery Add text to end of div and many articles relating to JQuery, JavaScript, asp.net, code snippets. Now I will explain how to get asp.net textbox or label value in JavaScript.

Get Asp.net Textbox or Label Value in JavaScript

To get asp.net textbox or label value in JavaScript we need to write a code like as shown below

Get label value

var amount = document.getElementById("<%=lblAmount.ClientID %>").innerHTML

Get label value

var name = document.getElementById("<%=txtUserName.ClientID %>").value;

If you want to see it in complete example check below code


<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>
Live Demo

To test live example click on below button

UserName
Amount

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

4 comments :

Manoj Kumar said...

Hi Suresh,

Some error in heading pls check,

Get label value

var amount = document.getElementById("<%=lblAmount.ClientID %>").innerHTML

Get textbox value

var name = document.getElementById("<%=txtUserName.ClientID %>").value;

ranadheerrannu said...

@manoj kumar: nice. He used "label" again instead of "textbox".

Articles Journal.com Growing Knowledge said...

its not working in Master's Content pages Why

Vakeel Mansoori said...

@manoj Kumar :put a semicolon(;) after .innerHtml of ur code

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.