How to get set value to asp textbox using jquery example


How to get set value to asp textbox using jquery example

jQuery is a javascript library which works at client side in the web browser. jQuery doesn't know about server controls. Let say when you request a page which contains asp textbox control or label control what happens at runtime, ASP.Net converts it to span html element while sending to the cient(browser).
server side and client side controls in

In this blog post I will demonstrate how to get/set value to asp textbox using jQuery with an example. Find the code below :-

how to get and set textbox value in jquery,how to get or set value of textbox using jquery,how to set value in textbox through jquery
get set value to asp textbox using jquery example
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="">
    <title>How to get set value to asp textbox using jquery</title>
    <script src="jquery.min.js"></script>
    <script type="text/javascript">
        var txtValue;
        function setTextBoxValue(e) {
            txtValue = $('#<%=txtName.ClientID%>').val();

        function getTextBoxValue(e) {
            alert($('#<%=lblResult.ClientID%>').html    ());

    <form id="form1" runat="server">
        <h1>Get or set the asp textbox value using jquery</h1>
        <div style="font-family:Verdana; font-size:16px;">
            <asp:Label ID="lblName" runat="server" Text="Enter your name: "></asp:Label>
            <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
            <br />
            <br />
            <asp:Label ID="lblResult" Font-Bold="true"  ForeColor="Maroon" runat="server" Text=""></asp:Label>
            <br />
            <br />
            <asp:Button ID="btnSetValue" runat="server" Text="Set Textbox Value" OnClientClick="return setTextBoxValue(event);" />
            <asp:Button ID="btnGetValue" runat="server" Text="Get Textbox Value" OnClientClick="return getTextBoxValue(event);" />

Note: If you notice the selector in the above code, I have used "ClientID" to get the value of the control. This is because Asp.Net controls are rendered as html controls in the browser. The "Id" will be not same as before. In this way we can get the Asp.Net TextBox or Label values using JQuery and other controls value.
How to get set value to asp textbox using jquery example Reviewed by Ravi Kumar on 8:55 PM Rating: 5

No comments:

All Rights Reserved by Etechpulse © 2012 - 2017

Contact Form


Email *

Message *

Powered by Blogger.