1

I've a Image in a UpdateProgress-Control combined with a ModalPopupExtender. To open the Extender when the site is loading, Iam using following Javascript:

<script type="text/javascript">
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(showPopup);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(hidePopup);

    function showPopup(sender, args) {
        var ModalControl = '<%= ModalPopupExtender1.ClientID %>';
        $find(ModalControl).show();
    }

    function hidePopup(sender, args) {
        var ModalControl = '<%= ModalPopupExtender1.ClientID %>';
        $find(ModalControl).hide();
    }
</script> 

This is working fine, but the Extender opens now every single Request. It only should open when a specific UpdatePanel was forced to refresh (UpdatePanelMain). How can I do it in Javascript like: if(postbackelement == UpdatePanelMain) or something?

Mike Trusov
  • 1,958
  • 1
  • 15
  • 23
Jendrik
  • 260
  • 3
  • 14

2 Answers2

1

To get the UpdatePanels id and find the one you won to let run you can use the args.get_postBackElement().id function as:

function showPopup(sender, args) {
     // get the Post ID and compare it with the one you let run
     if(args.get_postBackElement().id == "<%=UpdatePanelMain.ClientID%>")
     {
       var ModalControl = '<%= ModalPopupExtender1.ClientID %>';
       $find(ModalControl).show();
     }
}

similar question: How to get Id update panel that initial a request in javascript

Community
  • 1
  • 1
Aristos
  • 66,005
  • 16
  • 114
  • 150
  • Doesn't work for me. It says the args don't support the get_postBackElement function or the id is null. – Jendrik Nov 02 '12 at 08:00
  • @Jendrik Can you try that `var UpdPanelsIds = args.get_updatePanelsToUpdate();` to see if there is the id you looking for ? – Aristos Nov 02 '12 at 08:22
0

So this workaround is what I'm looking for. Thanks to Aristos for the hint.

var UpdPanelsIds = args.get_updatePanelsToUpdate();

if (UpdPanelsIds[0] != "") {
    if (UpdPanelsIds[0] != "ctl00$cpMain$UpdatePanelMenue" || args.get_postBackElement().id == '<%= refreshButton.ClientID %>') {
        var ModalControl = '<%= ModalPopupExtender1.ClientID %>';
        $find(ModalControl).show();
    }
}

Any conclusing how to make this code a little 'better'?

Jendrik
  • 260
  • 3
  • 14