Get (Retrieve) TextBox value inside UserControl using jQuery in ASP.Net

Last Reply 7 months ago By arunkurmi

Posted 7 months ago

How to get the value of textbox and any other control which is define inside user contral by using jquery

You are viewing reply posted by: arunkurmi 7 months ago.
Posted 7 months ago Modified on 7 months ago

Hi SajidHussa,

Check this sample. now take its reference.

UserControl.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs"
    Inherits="WebUserControl" %>
Enter Mobile No :
<input id="txtMobileNo" type="text" placeholder="Enter Your Registered Mobile Number" />

HTML

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("[id*=btnSubmit]").on("click", function () {
                var number = $('[id*=txtMobileNo]').val();
                alert(number);
            });
        });
    </script>
    <form id="form1" runat="server">
    <div>
        <uc1:UserControl ID="UserControl1" runat="server" />
        <br />
        <asp:Button ID="btnSubmit" Text="Submit" runat="server" />
    </div>
    </form>
</body>
</html>

Screenshot