Set Focus to Main Content in EP

Recently while working with a custom control in EP for AX 2012 I came across an issue when trying to set focus to a specific Textbox. I implemented all of the standard focus functions available in code, but none of them would retain focus when the control was running in the AX EP environment. I also tried a multitude of suggested fixes found on various Blogs with no luck. So I started my on investigation and the following is my findings.

I noticed that the target control would temporarily receive focus and then immediately lose it to a hidden system menu that exists at the top of the page. I dug deeper into this behavior and it led me to the DynamicsRestoreFocus java script that is available in the static file EPRestoreFocus. This script contains methods that are used to call focus to the various parts of an EP page.

I discovered that to force the page to set focus to the main content of the page that contains the user control you can paste the following code into the body definition of the master page that your new page references.

<script type="text/javascript">
$jQ(window).load(function(){DynamicsRestoreFocus.goToMainContent();});
</script>

I pasted it in at the bottom of the body portion of my master page. I believe that you may be able to add this code to your control somehow, but I’ve not had time to further investigate.

I have some code that should allow you to specify a specific target control as a parameter in a URL but it hasn’t been tested as my VM is in the process of a rebuild. As soon as I get a functioning version ready I will add it as a new post.

Share/Bookmark
This entry was posted in AX 2012, Enterprise Portal, Microsoft Dynamics AX and tagged , , , , , . Bookmark the permalink.