Hi, In Previous post we understood concept of JQuery and How to use JQuery in ASP.Net.
In this ASP.Net Jquery Post we will learn to Set text value to Label control and get value from Label control in ASP.Net.
First, Download JQuery library from http://jquery.com/. and include in web page at head section.
Design the ASP.Net web form with one Button and one Label control.
First, we will learn to get the Label control value when we click the button control.
Here, we assign label text = Meera Academy. when we click the button then label value shows in alert message box.
code for design asp.net web form:
<asp:Label ID=”Label1″ runat=”server” Text=”Meera Academy”></asp:Label>
<asp:Button ID=”Button1″ runat=”server” Text=”Get Label Value” />
write the below JQuery code for get the label value on button click event.
<head runat=”server”>
<title>JQuery in ASP.Net</title>
<script src=”jquery-1.4.3.min.js” type=”text/javascript”></script>
<script>
$(document).ready(function() {
$(“#Button1”).click(function() {
alert($(‘#<%=Label1.ClientID%>’).text());
});
});
</script>
</head>
The out put of above Jquery Example is :
Now, we will learn to set value to label control using JQuery. First clear the text value of label control.
we assign value “Meera Academy” to label control while clicking the Button control in asp.net.
code for design asp.net web form:
<asp:Label ID=”Label1″ runat=”server” Text=””></asp:Label>
<asp:Button ID=”Button1″ runat=”server” Text=”Set Label Value” />
In above figure we already removed the label text value.
write below JQuery code for assign value to Label control.
<head runat=”server”>
<title>JQuery in ASP.Net</title>
<script src=”jquery-1.4.3.min.js” type=”text/javascript”></script>
<script>
$(document).ready(function() {
$(“#Button1”).click(function() {
$(‘#<%=Label1.ClientID%>’).text(“Meera Academy”);
});
});
</script>
</head>
The Result of above JQuery Example is :
I hope this JQuery Exmaple Set and Get Value of Label control will help you….