【问题标题】:ASP.Net multiple UpdatePanel refresh with JavaScriptASP.Net 使用 JavaScript 刷新多个 UpdatePanel
【发布时间】:2011-08-30 22:47:46
【问题描述】:

我有一个 GridView 和一些允许用户展开单个行的 jQuery 代码。在行扩展时,我会显示一个 div,其中将包含与该行相关的更多信息。 div 内部是一个 ASP.Net UpdatePanel。我调用 __doPostBack 函数,传递我希望刷新的特定 UpdatePanel 的 ID。

var updatePanel = $(expandContent).children("div[id$=UpdatePanel1]").attr("id");
__doPostBack(updatePanel, '');

但是,在调试时,我注意到 *UpdatePanel_Load* 方法正在为页面上的每个 UpdatePanel 调用。由于扩展行将导致系统关闭并检索数据,我真的只想为已扩展的特定行获取此数据。

所以我的问题是,有没有人知道使用 JavaScript 使单个 UpdatePanel 刷新的方法。

谢谢 艾伦。

【问题讨论】:

    标签: javascript asp.net updatepanel


    【解决方案1】:

    如果我将 UpdatePanel 的 ID 传递给 __doPostBack 函数,例如:

    var updatePanel = $(expandContent).children("div[id$=UpdatePanel1]").attr("id");
    __doPostBack(updatePanel, updatePanel);
    

    在后面的代码中,我可以进行这样的测试,以确保仅针对特定的 UpdatePanel 进行检索:

    UpdatePanel panel = sender as UpdatePanel;
    
    // the ClientId of the UpdatePanel being update is passed in
    // __EVENTARGUMENT this can be checked against the sender to ensure
    // data is retrieved only for the row being expanded. 
    string panelID = Request.Params.Get("__EVENTARGUMENT");
    
    if(panel.ClientID.Equals(panelID))
    {
        // retrieve data
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-06
      • 1970-01-01
      • 1970-01-01
      • 2012-12-05
      • 1970-01-01
      • 2012-11-23
      • 1970-01-01
      相关资源
      最近更新 更多