在文本框中搜索关键字时,我将以前的结果作为输出

时间:2012-09-05 12:08:31

标签: javascript asp.net-ajax

主页表单

<form id="form1" runat="server">
    Search your keyword
    <asp:TextBox ID="search" onkeydown="javascript:doAJAX(this.value)"  runat="server">
    </asp:TextBox>
</form>

这是文本框搜索关键字的代码。按下某个键后,我的代码将发送输入的上一个键。我如何获得当前密钥? doAJAX函数inturn调用另一个aspx页面并填充此页面。

Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Try
        'Response.ContentType = "application/xhtml+xml"
        'Build CategoriesList
        Dim strSQL As String
        Dim Mytable As DataTable
        strSQL = "exec GetAJAXSearchResults '"
        strSQL &= Request("keyword")
        strSQL &= "', " & AppSettings("SiteId")
        Mytable = myLib.GetData(strSQL)



        For Each row As DataRow In Mytable.Rows
            'strChartList &= row.Item("title") & "<br/>"
            strChartList &= row.Item("PID") & "  " & row.Item("title") & "<br/>"
        Next row

        strChartList &= "</p>"

这是aspx代码,其中包含程序详细信息...我试图在if ...之前添加一个if语句但是没有工作..

1 个答案:

答案 0 :(得分:3)

onkeydown更改为onkeyup,以便在内容更改后触发

link。事件顺序:keydown(尚未插入符号),按键(插入符号的时刻),键盘 - 插入符号后

'Response.ContentType = "application/xhtml+xml"
    'Build CategoriesList
    Dim strSQL As String
    Dim Mytable As DataTable
    strSQL = "exec GetAJAXSearchResults '"
    strSQL &= Request("keyword")
    strSQL &= "', " & AppSettings("SiteId")
    strChartList &= "<p>" // see no opening tag in your code.
    If Not String.IsNullOrEmpty(Request("keyword")) And Request("keyword").Length() > 1 Then
      Mytable = myLib.GetData(strSQL)



       For Each row As DataRow In Mytable.Rows
          'strChartList &= row.Item("title") & "<br/>"
          strChartList &= row.Item("PID") & "  " & row.Item("title") & "<br/>"
      Next row
    End If
    strChartList &= "</p>"

应该像上面那样。对不起,如果声明不是来自VB,我只是不记得它在VB中应该是什么样子的细节。希望你能把C#if翻译成VB,如果