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

jQuery Get Set Text to Label or How to Get / Set Label Text in jQuery

Jun 12, 2013
Introduction

Here I will explain how to get or set text to label in jQuery or JavaScript or Get / set text to asp.net label control in jQuery or JavaScript.

Description:


Get Set html label Value in jQuery

To get html label value in jQuery we need to write the code like as shown below

Get html label value

var txt = $('#lbltxt').html();

Set html label value

$('#lbltxt').html("your value");
To Get asp.net label Value

To get asp.net label value we need to write the code like as shown below


var txt = $('#<%=lbltxt.ClientID%>').html();
or
var txt = $("[id$='lbltxt']").html()
Set Asp.net label Value


$('#<%= lbltxt.ClientID%>').html('Your Value')
Or
$("[id$=' lbltxt']").html('Your Value')
For Example check this post


<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="lbltxt" runat="server" >Welcome to aspdotnet-suresh.com</asp:Label>
<label ID="lblhtml" runat="server" >Welcome to html label</label>
<input type="button" id="btnclick" value="click" />
<script type="text/javascript">
$(function() {
$("#btnclick").click(function() {
var txt = $('#<%=lbltxt.ClientID%>').html();
var txthtml = $('#lblhtml').html();
alert(txt);
alert(txthtml);
})
});
</script>
</form>
</body>
</html>
Same way we can get any asp.net controls in JQuery


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

5 comments :

Anonymous said...

Hello Sir, This is abhinavsingh993, it is an Article that shows that you are a master of the asp.net

Vijay Kaliyaperumal said...

given the best solution in every time

thank you suresh

Anonymous said...

if want add value to label which is in gridview how it will..?

Anonymous said...

3

Anonymous said...

Thanks it worked for me! @anjankant

Give your Valuable Comments

Other Related Posts

© 2015 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.