确定是否与这部分回发发生在页面加载()的JavaScript在.NET这部、加载、页面、发生在

2023-09-03 04:02:14 作者:倾城之泪

据我了解,部分页面的更新与ASP.NET AJAX导致要调用的javacript页​​面加载()事件处理程序。

As I understand it, partial page updates with ASP.NET AJAX cause the javacript pageLoad() event handler to be invoked.

我的问题:有没有从页面加载()函数...

My question: Is there a generic way of determining in Javascript from within the pageLoad() function...

我)如果回发是一个局部页面更新与否。

i) If the postback was a partial page update or not.

二)如果是这样,哪个面板进行了更新。

ii) If so, which panel was updated.

我的应用程序使用.NET的UpdatePanel和放大器的组合;的Telerik RadAjaxPanels。我在寻找一个通用(preferably JavaScript)的解决方案,它不要求我指定一个唯一的客户端回调函数,每个小组,也没有设置一些标志,从每个回发事件处理程序中,以确定自己的客户端 - 侧。

My application uses a combination of .NET UpdatePanels & Telerik RadAjaxPanels. I'm looking for a generic (preferably javascript) solution which doesn't require me to specify a unique client-side callback function for each panel, nor set some flag from within each postback event handler to identify itself to the client-side.

我希望这是有道理的,

感谢。

推荐答案

要或确定是否回发是部分更新没有,你可以使用 ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack 。这里有一个例子:

To determine if the postback was a partial update or not, you can use ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack. Here's an example:

protected void Page_Load(object sender, EventArgs e)
{
    if (Page.IsPostBack)
    {
        // get a reference to ScriptManager and check if we have a partial postback
        if (ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)
        {
            // partial (asynchronous) postback occured
            // insert Ajax custom logic here
        }
        else
        {
            // regular full page postback occured
            // custom logic accordingly                
        }
    }
}

和获取导致回发更新面板,你可以看看 ScriptManager.GetCurrent(页).UniqueID 并进行分析。下面是这样做的一个例子:

And to get the Update Panel that caused the PostBack, you can look into ScriptManager.GetCurrent(Page).UniqueID and analyze it. Here's an example of doing that:

public string GetAsyncPostBackControlID()
{
    string smUniqueId = ScriptManager.GetCurrent(Page).UniqueID;
    string smFieldValue = Request.Form[smUniqueId];

    if (!String.IsNullOrEmpty(smFieldValue) && smFieldValue.Contains("|"))
    {
        return smFieldValue.Split('|')[0];
    }

    return String.Empty;
}

参考文献:

http://forums.asp.net/t/1562871.aspx/1 Get ASP.NET控制,燃煤中的AJAX的UpdatePanel 回传 http://forums.asp.net/t/1562871.aspx/1 Get ASP.NET control which fired a postback within a AJAX UpdatePanel