Assign Value to TextBox Control using JQuery in ASP.Net

Now,  we understood the concept of JQuery and How to use JQuery in ASP.Net.

In this ASP.Net Jquery Post we will learn to Assign value to TextBox 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 TextBox control.

First, clear the TextBox control text value, when we click button then assign value to TextBox control.

write below code for design asp.net web form:

<asp:TextBox ID=”TextBox1″ runat=”server” Height=”24px” Width=”140px”></asp:TextBox>
<asp:Button ID=”Button2″ runat=”server” Text=”Assign Value” />

The out put of design asp.net web form :

Assign text vlaue to TextBox control using JQuery in ASP.Net.
Assign text vlaue to TextBox control using JQuery in ASP.Net.

Now, Write below JQuery code for assign value to Textbox 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() {
$(‘#<%=TextBox1.ClientID%>’).val(“Meera Academy”);  
});
});
</script>
</head>

The Result of JQuery Example  is :

Assign text vlaue to TextBox control using JQuery in ASP.Net.
Assign text vlaue to TextBox control using JQuery in ASP.Net.

Now , we learn to get value from Textbox using JQuery.

Get value from TextBox syntax :

$(‘#<%=TextBox1.ClientID%>’).val();

I hope this JQuery Textbox Example will help you….

 

Leave a Reply

Your email address will not be published. Required fields are marked *