þÍńķ þÍńķ -4 years ago 172
ASP.NET (C#) Question

How to Find UserControls Control value in Jquery Asp.net?

I am using jQuery and ASP.net

I have a User Control and wanted to Set the values of this User control to the database, for that I need the user control's value. In the same way, I want to show the data from the database in the user control, for that I need to Get the values by jquery.

In my user control I have 4 TextBoxes and 2 Buttons (SET/UPDATE)

AutoCompleteSearch_New is ascx user control

Here is my tried code:

var ID = $('#<%= ((HiddenField)AutoCompleteSearch_New.FindControl("hdnvalue")).ClientID %>').val();

But I dont wan't to use hidden fields.

Can I directly find the control's value without using hidden fields?

Answer Source

It is similar to use value from a webform.

Here is the code for the same.

 Var TextBoxValue = $('#YourTextBoxID').val();

Inspect element and get the Textbox ID and replace it with YourTextBoxID.


Var TextBoxValue = $('#<%= YourTextBoxID.ClientID').val();

where YourTextBoxID is your asp:Textbox ID.

When ever you load user control in your aspx page, jquery consider it as a whole page which is combined of user control and rest of the aspx controls exist in the form. So you can directly get textbox value in your jquery

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download