小编典典

如何获取在javascript中初始化请求的ID更新面板

ajax

我想知道Id更新面板使用JavaScript初始化请求。我编写了此脚本,但返回了undefined

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);

function InitializeRequest(sender, args) {
    alert(sender.ID);
}
function EndRequest(sender, args) {
}

sender不为null,它返回[object]但我如何获得ID


编辑1)

我认为当它UpdatePanel在里面MasterPage不起作用时,这是我的代码:

<script type="text/javascript">
    $(document).ready(function () {
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_initializeRequest(InitializeRequest);
        prm.add_endRequest(EndRequest);


        function InitializeRequest(sender, args) {
            var UpdPanelsIds = args.get_updatePanelsToUpdate();
            alert(UpdPanelsIds[0]);
        }
        function EndRequest(sender, args) {
            if ($('.AlarmLogo').val() == "3") {
                alert('nima');
            }
        }
    });


</script>

和:

<form runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="timer" Interval="4000" runat="server" OnTick="timer_Tick" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Panel ID="pnlAlarm" runat="server" CssClass="pnlAlarm" ClientIDMode="Static">
            <a href="#">
                <div id="Alarm">
                    <asp:TextBox ID="lblContent" runat="server" Text="HHHEEELLLOOO" CssClass="AlarmLogo" ClientIDMode="Static"></asp:TextBox>
                </div>
            </a>
        </asp:Panel>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="timer" />
    </Triggers>
</asp:UpdatePanel>
    <div class="main">
        <asp:ContentPlaceHolder ID="MainContent" runat="server" />
    </div>
</form>

和后面的代码:

protected void Page_Load(object sender, EventArgs e) 
{     
    if (!IsPostBack)     
    {         
        Session["nima"] = 1;    
    } 
}

protected void timer_Tick(object sender, EventArgs e) 
{    
}

阅读 238

收藏
2020-07-26

共1个答案

小编典典

您可以使用,get_updatePanelsToUpdate该返回的数组包含将要更新的UpdatePanels的ID。

<script>
    window.onload = function() {
        var prm = Sys.WebForms.PageRequestManager.getInstance();

        prm.add_initializeRequest(InitializeRequest);
        prm.add_endRequest(EndRequest);
    };

      function InitializeRequest(sender, args) 
      {     
         // get the array of update panels id
         var UpdPanelsIds = args.get_updatePanelsToUpdate();
         // get the Post ID
         args.get_postBackElement().id;
      }

      function EndRequest(sender, args) {
      }
</script>

http://msdn.microsoft.com/en-
us/library/ee224805.aspx

2020-07-26