Select to view content in your preferred language

Add-in Button OnUpdate() is not Called

2786
5
03-31-2011 07:07 AM
joshoman
Emerging Contributor
Hello,
I created a simple add-in Button that opens a mxd document. The button uses the OnUpdate() event to check when the document is finished opening and then runs some additional code. The Button worked as expected until I moved it's Config.esriaddinx entry from <Toolbar></Toolbar> to a <Menu></Menu> (drop-down menu).  Since moving the Button to a drop-down menu, the OnUpdate() function does not get called.  However, the OnUpdate() function is eventually called when I click the drop down menu that contains the button.  Is this expected behavior for the OnUpdate() event?  I'd like to know why the Button's OnUpdate() behavior is different between toolbar UI styles. 

Thanks,
Josh
0 Kudos
5 Replies
KenBuja
MVP Esteemed Contributor
Have you added the OnDemand attribute to the button in the Config.esriaddinx file? See the help for more information about Delay loading
0 Kudos
joshoman
Emerging Contributor
Thanks for the response.  I set the ondemaned property to false, but the behavior is the same.  The problem is happening after the user clicks the button, so it seems preloading the button shouldn't make a difference. From debugging I can see the OnUpdate() function is only being called when the mouse is clicking or hovering on the drop down menu.  The Button's OnUpdate() function is not called when the it is not visible because the dropdown menu is collapsed.  Is this expected behavior, a bug?  Is there a similar method I can use to periodically check if the mxd has finished opening?

Thanks,
Josh
0 Kudos
KenBuja
MVP Esteemed Contributor
This makes me wonder if the menu's OnDemand also needs to be set.
0 Kudos
joshoman
Emerging Contributor
The menu does not have an "ondemand" property.  The menu is basically just xml tags that ArcMap uses to organize add-in controls on the toolbar. As far as I know the menu is not an object that can be extended or accessed with ArcObjects.  Here is a generic example of my Config.esriaddinx code:

<Commands>
        <Button id="Setup" class="SetupButton" message="Creates a copy of an mxd and opens opens it" caption="none" image="Images\SetupButton.png" onDemand="false"/>
</Commands>

<Menus>
        <Menu id="Data_Prep" caption="Data Prep" isRootMenu="true">
          <Items>
            <!-- OnUpdate() is NOT called periodically on this Setup button -->
            <Button refID="Setup" />
            <Button refID="PrepData" />
            <Button refID="Load_Data1" />
            <Button refID="Load_Data2" />
            <Button refID="DeleteData" />
          </Items>
        </Menu>
</Menus>

<Toolbars>
        <Toolbar id="Toolbar" caption="Toolbar" showInitially="false" >
          <Items>
            <Menu refID="Data_Prep" />
  <!-- OnUpdate() is called periodically on this Setup button -->
            <Button refID="Setup" />
          </Items>
        </Toolbar>
</Toolbars>


Thanks,
-Josh
0 Kudos
joshoman
Emerging Contributor
This seems to be a bug, so I've opted for a workaround.  I was able to get the behavior I needed by using ESRI.ArcGIS.ArcMapUI.IDocumentEvents_OpenDocumentEventHandler.  Still, I prefer the OnUpdate() method since it was cleaner.  Thanks for the help.

-Josh
0 Kudos