Microsoft Silverlight – Setting Initial Focus on Silverlight Control

Even though you may have set focus to your first enterable textbox in a Silverlight Control, it will not truly receive the focus until the actual Silverlight control has focus first.

In order to do this, add a few lines of javascript in the the section of the main *.aspx document (Web Client) and you are good to go. The default name of the initial Silverlight XAML document will be ‘Xaml1’.

The code:

<script type="text/javascript">
window.onload = function()
{
document.getElementById('Xaml1').focus();
}
</script>;
Please follow and like us: