将数据返回到没有回发的文本框中

returning data into textboxes without postback

我有一个表格,其中有一个参考编号和一个备注字段。像这样:

Ref Notes

在我的数据库中有多个行:

1234 | Note1 | 20/03/2013 18:44 1234 | Note2 | 20/03/2013 18:45

我想在我的文本框中显示最近的笔记。但我也需要显示参考编号。

我能做到:

SqlConnection Conn = new SqlConnection(Connection_String);
SqlCommand Comm1 = new SqlCommand(Command, Conn);
Conn.Open();
SqlDataReader DR1 = Comm1.ExecuteReader();
if (DR1.Read())
{
    textBox.Text = DR1.GetValue(0).ToString();
}
Conn.Close();

但是有没有更优雅的解决方案,允许我在不回发的情况下在每条记录之间单击?

如果您要避免完全回发,您将使用 Ajax(异步 JavaScript 和 XML 的缩写)。

您有两个受欢迎的选择

  1. 使用 ASP.Net 框架附带的 Microsoft Ajax 实现并利用 UpdatePanel 和其他控件
  2. 使用jQuery Ajax

如果你对jQuery中使用的jQuery库和数据结构有一些想法,最好使用更易于使用的jQuery Ajax .

来自jQuery - AJAX Introduction

‘Writing regular AJAX code can be a bit tricky, because different browsers have different syntax for AJAX implementation. This means that you will have to write extra code to test for different browsers. However, the jQuery team has taken care of this for us, so that we can write AJAX functionality with only one single line of code.’

参考资料

channel9.msdn.com - How Do I: Make Ajax Calls Using jQuery?