[Solved] Get textbox value in jquery on button click asp.net and Html

In this tutorial, I am going to show with you how to "get textbox value in Jquery on button click".  Here I am taking both controls(Asp.net and HTML) to get textbox value. So let's get started. Some we unable to get the value of the textbox control because of the wrong method to call the textbox ID. 

Get textbox value in jquery on button click asp.net and Html



Step to get textbox value on button click.
1. Use Jquery.min.js URL.
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
2. Always use # and .ClientID to get asp.net textbox value.





<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DemoJquery.aspx.cs" Inherits="DemoJquery" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
    <title>get textbox value in Jquery on button click</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
        $(document).ready(function () {
            $('#<%=btnAsp.ClientID%>').click(function () {
                var i = $('#<%=ASPtxtbox.ClientID%>').val()
                alert(i);
            });
        });
    </script>

    <script>
        $(document).ready(function () {
            $("#btnHTML").click(function ()
            {
                var i = $("#HTMLtxtbox").val();
                alert(i);
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <td>get textbox value in Jquery on button click with Asp.net control</td>
                    <td>
                        <asp:TextBox ID="ASPtxtbox" runat="server"></asp:TextBox>
                        <asp:Button ID="btnAsp" runat="server" Text="Asp.Net Button" />
                    </td>
                </tr>

                <tr>
                    <td>get textbox value in Jquery on button click with HTML control</td>
                    <td>
                        <input type="text" id="HTMLtxtbox" />
                        <button type="button" id="btnHTML">
                            Html Button
                        </button>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>


 Hope you like this tutorial, if you have any problem feel free to comment below.

Post a Comment

Post a Comment (0)

Previous Post Next Post