0

我正在研究搜索功能,并受到后端的限制。我试图通过进行多次小搜索而不是一次大搜索来加快速度。我目前正在做的是在 OnClick 事件中,首先进行搜索并将结果返回到 gridview。如果有更多的搜索要做,我使用 AjaxControlToolkit.ToolkitScriptManager.RegisterStartupScript 注册一个再次单击提交按钮的小函数。

这可行,但似乎是一种黑客行为,我觉得应该有更好的方法。我错过了什么吗?

4

2 回答 2

1

The first option that comes to mind is an extra layer of complexity but would probably gain your the best user experience by using ajax to pull sets of results as many times as needed using a small service to provide the data. I provided that example with a little bit of jquery to show the call.

searchRequest = $.ajax({
            url: '/GetSearchData.svc',
            data: { searchText: 1 },
            traditional: true,
            success: function(data) {

                // Do something with returned data or kick off another async request
        });

This would allow you to pull the raw data in any size or chunks that you want. Or to attach them to another event such as scroll to add items over time.

于 2012-12-06T21:51:16.710 回答
0

我最终使用了这样的计时器:

    <asp:Timer runat="server" ID="timer1" Interval="1000"
   ontick="timer1_Tick" Enabled="false" />

然后在 Button 的 onClick 事件中,我启动了一个线程来执行搜索并启动计时器。

timer1.Enabled = true;
ThreadStart ts = continueSearch;
Thread thread = new Thread(ts);
thread.Start();

在 timer1_Tick 处理程序中:

if(Session["SearchResults"] != null)
{
    DataView dv = (DataView)Session["SearchResults"];
    dv.Sort = (string)Session["SortExpression"] + (string)Session["SortDirection"];
    gvResults.DataSource = dv;
    gvResults.DataBind();
}
于 2012-12-11T18:12:53.090 回答