Getting focus on Silverlight control on load

When we host a Silverlight application inside a ASP.Net page and set a focus on a control inside Silverlight application, we would except the control to get the focus, but that does not happen automatically. One way it can be achieved by adding a on load script to the Silverlight object and make the Silverlight object get the focus.

<param name=”onLoad” value=”onLoad” />

function onLoad(sender, args)

{

   var silverlightObject = document.getElementById(“silverlightObject”);

   if (silverlightObject != null)

      silverlightObject.focus();

}

make sure you name the Silverlight object as ‘silverlightObject’ or replace the onload script with the name of the silverlight object.

Technorati Tags: ,

Advertisements