如何找到jQuery的Asp.net用户控件控制价值? [英] How to Find UserControls Control value in Jquery Asp.net?
问题描述
我使用jQuery和ASP.net
I am using jQuery and ASP.net
我有一个用户控件,并希望这个用户控件的值设置为数据库,我需要的用户控件的值。以同样的方式,我想显示在用户控件从数据库中的数据,对于我需要jQuery来获取值。
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.
在我的用户控件我有4个文本框和按钮2(SET / UPDATE)
In my user control I have 4 TextBoxes and 2 Buttons (SET/UPDATE)
AutoCompleteSearch_New是ASCX用户控件
AutoCompleteSearch_New is ascx user control
下面是我试过code:
Here is my tried code:
var ID = $('#<%= ((HiddenField)AutoCompleteSearch_New.FindControl("hdnvalue")).ClientID %>').val();
但我不wan't使用隐藏域。
But I dont wan't to use hidden fields.
我可以直接找到该控件的值,而不使用隐藏域?
Can I directly find the control's value without using hidden fields?
推荐答案
这是一个类似从一个WebForm利用价值。
It is similar to use value from a webform.
下面是code为相同。
Here is the code for the same.
Var TextBoxValue = $('#YourTextBoxID').val();
检查元素,并得到文本框的ID和 YourTextBoxID
替换它。
或者
Var TextBoxValue = $('#<%= YourTextBoxID.ClientID').val();
其中, YourTextBoxID
是你的ASP:文本框ID
where YourTextBoxID
is your asp:Textbox ID.
当你永远在你的aspx页面加载用户控件,jQuery的认为这是它的控制相结合的形式存在ASPX用户控制和休息的一整页。所以,你可以直接在你的jQuery获取文本框的值
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
这篇关于如何找到jQuery的Asp.net用户控件控制价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!