无法从html输入中检索值(自动完成jquery ui)

时间:2014-01-31 13:18:25

标签: c# html visual-studio extract

我有一个html自动填充文本框,我的问题是当我尝试输入地址时,例如。 “纽约”并单击提交按钮。它不检索输入值。(不返回任何值)

Test.aspx文件

<!--Address-->
    <div class="form-group">
         <label class="col-sm-3 control-label no-padding-right">Address</label>
         <div class="col-sm-7">

            <input id="tb_address" type="text" class="form-control" placeholder="Type 'a' or 'h'" />

    </div>
</div>

我在Test.aspx页面中的javascript代码

<script type="text/javascript">
        jQuery(function ($) {


            //custom autocomplete (category selection)
            $.widget("custom.catcomplete", $.ui.autocomplete, {
                _renderMenu: function (ul, items) {
                    var that = this,
                    currentCategory = "";
                    $.each(items, function (index, item) {
                        if (item.category != currentCategory) {
                            ul.append("<li class='ui-autocomplete-category'>" + item.category + "</li>");
                            currentCategory = item.category;
                        }
                        that._renderItemData(ul, item);
                    });
                }
            });

            var data = [
               { label: "New York", category: "North" },
           { label: "Rochester", category: "North" },
           { label: "California", category: "North" },

            ];
            $("#tb_address").catcomplete({
                delay: 0,
                source: data
            });




        });
    </script>

protected void bn_Submit_Click(object sender, EventArgs e)
{
  string address = Request.Form["tb_address"];

   lb_msg.Text = address;
}

1 个答案:

答案 0 :(得分:1)

我看到您的输入没有名称,请按如下方式调整输入标记,然后重试:

<input id="tb_address" name="tb_address" type="text" class="form-control" placeholder="Type 'a' or 'h'" />