如何设置输入按钮onserverclick?

时间:2018-01-16 12:13:02

标签: javascript asp.net

<div class="input-append">
    <input type="text" id="txtSearch" name="txtSearch" class="autosuggest span10 classic-search" autofocus="true" tabindex="1" />
    <button class="btn" type="button" id="SchButton" onserverclick="GetDistributorRegNo" runat="server">
        <i class="icon-search"></i>
    </button>
</div>

我想按回车键搜索内容。但我有onserverclick没有jquery的工作。

1 个答案:

答案 0 :(得分:1)

您需要将输入和按钮包装在这样的表单标记中:

 <form id="form1" method="post" runat="server">
    <div class="input-append">
        <input type="text" id="txtSearch" name="txtSearch" class="autosuggest span10 classic-search" autofocus="true" tabindex="1" />
       <button class="btn" type="submit" id="SchButton" onserverclick="GetDistributorRegNo" runat="server">
        <i class="icon-search"></i>
      </button>
    </div>
</form>

现在,当您按Enter键时,它将调用onserverclick="GetDistributorRegNo"并将表单数据发送到服务器。

编辑:您的代码背后应该看起来像这样接收表单数据

 protected void Page_Load(Object Source, EventArgs E)   
  {   
    if (IsPostBack)   
    {   
      // Process Form data here...   
    }       
  }