Saturday, July 9, 2011

Get textbox server control value using jquery in asp.net

Retrieve the server control id in the java script (jQuery code) and do as usual
jQuery code for getting the value at the ASPx page.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="scripts/jquery-1.6.1.min.js" type="text/javascript"></script>
    <script type = "text/javascript">
        $(document).ready(function () {

            $("#<%= btnSend.ClientID %>").click(function () {
                alert($("#<%= txtInfo.ClientID %>").val());
                return true;
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style=" margin : 0px auto">
        <asp:TextBox ID="txtInfo" runat="server"></asp:TextBox>
        <
asp:Button ID="btnSend"  runat="server" Text="Send" />
    </div>
    </form>
</body>
</html>


1 comment :