Friday 11 June 2010

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.

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

 

    1. function onLoad(sender, args)
    2. {
    3.    var silverlightObject = document.getElementById(“silverlightObject”);
    4.    if (silverlightObject != null)
    5.       silverlightObject.focus();
    6. }

 

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

0 comments:

Post a Comment