If you have a Asp.Net TextBox or Label then you can get the value of that textbox/label using Jquery.
Lets say you have a asp.net textbox like below
Lets say you have a asp.net label like below
Note: If you notice the selector in the above code, we are using "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 what you have given to that control.
So if you simply write $("#txtName") it won't work. We use that syntax to get the value of a HTML input(type="text") element.
In this way we can get the Asp.Net TextBox or Label values using JQuery.
Get TextBox value with jquery:
<asp:TextBox ID="txtName" runat="server" />
then you can get the value of the above textbox using JQuery using the below codevar name = $("#<%=txtName.ClientID %>").val();
Get Label value with jquery :
Lets say you have a asp.net label like below
<asp:Label ID="lblName" runat="server" Text="codeSolver"/>
then you can get the value of the above label using JQuery using the below codevar name = $("<%=lblName.ClientID %>").html();
Note: If you notice the selector in the above code, we are using "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 what you have given to that control.
So if you simply write $("#txtName") it won't work. We use that syntax to get the value of a HTML input(type="text") element.
In this way we can get the Asp.Net TextBox or Label values using JQuery.