1

我需要在一个 aspx 页面上填充 4 个 GridView,但我只在页面加载时将一个数据表绑定到其中一个。我需要在页面加载后填充其他 3 个。

有谁知道使用 ajax 的最佳方法?

目前我在一个按钮上使用 javascript 来 __doPostBack,它 pupulates 3 GridViews 但不幸的是,即使使用更新面板,这也会强制加载整个页面。我需要加载页面,然后在返回数据表时填充 GridView。

任何建议将不胜感激。

4

2 回答 2

2

The way you are doing it should work ok, although using jquery to populate a div via the $("#targetDiv").load("contentUrl"); function may be a cleaner way to do it. Anyway, in order to get your current implementation working, there could be a few things you want to look at:

  1. I assume EnablePartialRendering is true on your ScriptManager (always worth checking!).
  2. Make sure the eventTarget for the __dopostback call is set up as an async trigger for your update panels or that it is inside the UpdatePanel if you are only using one UpdatePanel. (See here for details)
  3. Try returning false from the javascript code that executes in the onclick event handler if you have attached this to a button, to make sure the form is not being submitted normally by your browser when you click the button.
于 2009-04-16T12:44:57.583 回答
0

如果我正确理解了这个问题,您希望在页面进入浏览器后加载数据。如果是这种情况,那么您可以在页面加载到客户端时使用 JavaScript 触发事件。

我使用的一种方法是在页面上放置一个隐藏的(使用 CSS,而不是任何属性)按钮并使用 javascript“单击”它。按钮单击事件的事件需要在页面的代码中连接。此外,该按钮必须位于更新面板中,该面板要么包含您要绑定的网格,要么具有适当的触发器以使它们重新加载。

当此代码被触发时,您可能会查看 JQuery 以进行管理。$(document).ready(function(){ /* 你的代码在这里... */ }); 方法将在整个 DOM 可用后触发,这比等待整个页面加载(图像等)要快。

于 2009-04-16T12:29:59.630 回答