Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将值从Jquery传递到Asp.net代码隐藏文件?_Jquery_Asp.net_Html_C# 4.0 - Fatal编程技术网

如何将值从Jquery传递到Asp.net代码隐藏文件?

如何将值从Jquery传递到Asp.net代码隐藏文件?,jquery,asp.net,html,c#-4.0,Jquery,Asp.net,Html,C# 4.0,我有一个单选按钮,我在每个单选按钮上存储了一些值 $(document).on('change', '.vEditTamplateId', function () { var vpath = ""; $(".vEditTamplateId").each(function () { if ($(this).is(":checked") == true) { vpath = $(this).attr('idd'

我有一个单选按钮,我在每个单选按钮上存储了一些值

$(document).on('change', '.vEditTamplateId', function ()
{
        var vpath = "";
        $(".vEditTamplateId").each(function () {
            if ($(this).is(":checked") == true) {

                vpath = $(this).attr('idd');
                $('input[id$=hdnEmpName]').val(vpath);
            }
        })

});
这是我的密码

我已使用此asp.net服务器端控件

<input type="hidden" id="hdnEmpName" runat="server" />
我总是得到这个空值

请给我提个适当的建议。

简单的方法
[WebMethod]
公共列表GetAutoCompleteData(字符串用户名)
{
列表结果=新列表();
使用(SqlConnection con=newsqlconnection(System.Configuration.ConfigurationManager.ConnectionStrings[“ERP\u ConnectionString”].ToString())
{
string query=“从tablename中选择代码,[Description],其中Compcode='01'和类似“%”+@SearchText+'%”的描述;
使用(SqlCommand cmd=newsqlcommand(query,con))
{
con.Open();
cmd.Parameters.AddWithValue(“@SearchText”,用户名);
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
Add(string.Format(“{0}/{1}”、dr[“Code”]、dr[“Description”]);
}
}
}
返回结果;
}

您能否补充一些解释,说明为什么这是正确的解决方案?代码可能很好,但解释为什么可能有助于解决最初的问题。这与OP的问题有什么关系?它只是向服务器端发送客户端值以获得帮助。显然OP并没有尝试使用AJAX,只是尝试将值添加到隐藏字段中。发布一个完全不相关的例子是没有帮助的。你能用css类“vEditTamplateId”显示元素的标记吗?你可以在上面迭代吗?另外,回发是如何完成的?
            string vPath = hdnEmpName.Value;
    function SearchText() {
        $(".autosuggest").autocomplete({
            source: function (request, response) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "AutoSearchTest.asmx.cs/GetAutoCompleteData",
                    data: "{'username':'" + document.getElementById('txtSearch').value + "'}",
                    dataType: "json",
                    success: function (data) {
                        response($.map(data.d, function (item) {
                            return {
                                label: item.split('/')[0],
                                val: item.split('/')[1]
                            }
                        }));
                    },
                    error: function (xhr, status, error) {
                        alert("Error: " + xhr.responseText);
                    }
                });
            },
            select: function (event, ui) {
                $('#lblUserId').text(ui.item.val);
            }
        });
    }
[WebMethod]
public List<string> GetAutoCompleteData ( string username )
{
    List<string> result = new List<string>();
    using ( SqlConnection con = new SqlConnection( System.Configuration.ConfigurationManager.ConnectionStrings[ "ERP_ConnectionString" ].ToString() ) )
    {

        string query= "SELECT Code, [Description] from tablename Where Compcode = '01' and Description LIKE '%'+@SearchText+'%'";
        using ( SqlCommand cmd = new SqlCommand( query, con ) )
        {
            con.Open();
            cmd.Parameters.AddWithValue( "@SearchText", username );
            SqlDataReader dr = cmd.ExecuteReader();
            while ( dr.Read() )
            {
                result.Add( string.Format( "{0}/{1}", dr[ "Code" ], dr[ "Description" ] ) );
            }
        }
    }
    return result;
}