如何获得的UpdatePanel的这启动了回发的ID [英] How to get the id of Updatepanel which initiated a postback

查看:127
本文介绍了如何获得的UpdatePanel的这启动了回发的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我需要拦截后uDate公司面板异步回发的服务器回调,并确定哪些面板发起请求。在code是pretty简单:

Hi I need to intercept server callback after udate panel async post back and determine which panel initiated the request. The code is pretty simple:

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(InterceptUpdateCallback);

function InterceptUpdateCallback(sender, args)
{
    var updatedPanels = args.get_panelsUpdated();    
    for (idx = 0; idx < updatedPanels.length; idx++) {
        if (updatedPanels[idx].id == "myUpdatePanel") {            
            StartSmth();
            break;
        }
      }
}

和它的工作原理时,UpdatePanel的不是另一个UpdatePanel内。但是,当它是另一种的UpdatePanel updatedPanels [IDX] .ID内部有父UpdatePanel的ID。所以,我怎么能得到的UpdatePanel的其中发起请求(内部的UpdatePanel)的ID?感谢名单

And it works when UpdatePanel is not inside another UpdatePanel. But when it is inside another UpdatePanel updatedPanels[idx].id has parent Updatepanel id. So how can I get the id of UpdatePanel which initiated the request (the inner UpdatePanel)? Thanx

推荐答案

在这里你去:

function InterceptUpdateCallback(sender, args) {
 if (sender._postBackSettings)
    alert(sender._postBackSettings.panelID);
 else
    alert('first load');    
}

更新:

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    protected void LinkButtons_Click(object sender, EventArgs e)
    {
        LabelMain.Text = LabelSub1.Text = LabelSub2.Text = LabelSub3.Text = string.Format("{0} Updated By {1}", DateTime.Now, ((Control)sender).ID);
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <style type="text/css">
        body { font-family: Tahoma;}
        fieldset { padding: 15px; }
        fieldset a 
        {
            float: right;
            clear: none;
            display: block;
            margin: 10px;
        }
        fieldset span
        {
            display: block;
            margin-top: 20px;
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <script type="text/javascript">
        function pageLoaded(sender, args) {
            if (sender._postBackSettings) {
                var panelId = sender._postBackSettings.panelID.split('|')[0];
                if (panelId == sender._scriptManagerID) {
                    var updatedPanels = args.get_panelsUpdated();
                    var affectedPanels = "Affected Panels:\n";
                    for(var x=0;x<updatedPanels.length;x++)
                        affectedPanels+= updatedPanels[x].id + "\n";
                    alert("Request initiated by ScriptManager\n\nMight be an async trigger, or child of an update panel with children as triggers set to false.\n\n"+affectedPanels);
                }
                else
                    alert("Request initiated by: " + panelId);
            }
        }
        Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);
    </script>

    <asp:LinkButton ID="UpdateMain" runat="server" Text="UpdateMain" OnClick="LinkButtons_Click"></asp:LinkButton>,
    <asp:LinkButton ID="UpdateSub1" runat="server" Text="UpdateSub1" OnClick="LinkButtons_Click"></asp:LinkButton>,
    <asp:LinkButton ID="UpdateSub2" runat="server" Text="UpdateSub2" OnClick="LinkButtons_Click"></asp:LinkButton>,
    <asp:LinkButton ID="UpdateSub3" runat="server" Text="UpdateSub3" OnClick="LinkButtons_Click"></asp:LinkButton>
    <br />
    <br />
    <asp:UpdatePanel ID="Main" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
        <ContentTemplate>
            <fieldset>
                <asp:LinkButton ID="LinkButton1" runat="server" Text="LinkButton1" OnClick="LinkButtons_Click"></asp:LinkButton>
                <legend>Main -  Update Mode:Conditional, Children As Triggers:False</legend>
                <asp:Label ID="LabelMain" runat="server" Text="LabelMain"></asp:Label>
                <asp:UpdatePanel ID="Sub1" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
                    <ContentTemplate>
                        <fieldset>
                            <asp:LinkButton ID="LinkButton2" runat="server" Text="LinkButton2" OnClick="LinkButtons_Click"></asp:LinkButton>
                            <legend>Sub1 - Update Mode:Always, Children As Triggers:True</legend>
                            <asp:Label ID="LabelSub1" runat="server" Text="LabelSub1"></asp:Label>
                            <asp:UpdatePanel ID="Sub2" runat="server"  UpdateMode="Always" ChildrenAsTriggers="true">
                                <ContentTemplate>
                                    <fieldset>
                                        <asp:LinkButton ID="LinkButton3" runat="server" Text="LinkButton3" OnClick="LinkButtons_Click"></asp:LinkButton>
                                        <legend>Sub2 - Update Mode:Always, Children As Triggers:True</legend>
                                        <asp:Label ID="LabelSub2" runat="server" Text="LabelSub2"></asp:Label>
                                    </fieldset>
                                </ContentTemplate>
                                <Triggers>
                                    <asp:AsyncPostBackTrigger ControlID="UpdateSub2" />
                                </Triggers>
                            </asp:UpdatePanel>                            
                        </fieldset>                        
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="UpdateSub1" />
                    </Triggers>
                </asp:UpdatePanel>
                <asp:UpdatePanel ID="Sub3" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
                    <ContentTemplate>

                        <fieldset>
                            <asp:LinkButton ID="LinkButton4" runat="server" Text="LinkButton4" OnClick="LinkButtons_Click"></asp:LinkButton>
                            <legend>Sub3 - Update Mode:Conditional, Children As Triggers:False</legend>
                            <asp:Label ID="LabelSub3" runat="server" Text="LabelSub3"></asp:Label>
                        </fieldset>                        
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="UpdateSub3" />
                    </Triggers>
                </asp:UpdatePanel>
            </fieldset>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="UpdateMain" />
        </Triggers>
    </asp:UpdatePanel>
    </form>
</body>
</html>

这篇关于如何获得的UpdatePanel的这启动了回发的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆