Using jquery defer to wait until a variable is ready to be returned to silverlight app.

Answered Using jquery defer to wait until a variable is ready to be returned to silverlight app.

  • Wednesday, April 10, 2013 4:31 PM
     
      Has Code

    I am expecting some sort of sync operation when javascript is called via HtmlPage.Invoke but this is not working.

    Here is my javascript code, that should return a variable once it is available but instead it returns the object.

    	var searchDfrd;
    
    		function setPoint(val) {
    			searchDfrd.resolve(val);
    			$("#popupWin").popup('close');
    		}
    		function callmeonPageLoad(callback) {
    			
    			$("#popupWin").popup('open');
    			searchDfrd = $.Deferred().done(function (val) {
    				console.log(val);
    			});
    			return searchDfrd.promise();
    	  }
    		
    	


    And here is my c# code in silverlight that calls the above method.

    string expressionVal = (string)HtmlPage.Window.Invoke("callmeonPageLoad");

    As you can see above, 

    searchDfrd.promise();

    this line is supposed to wait until variable is resolved and return simple string when its ready, instead it returns immediately.

    Please help.

All Replies

  • Thursday, April 11, 2013 6:30 AM
     
     Answered
    I solved it myself. I exposed a silverlight managed function to javascript and called it when I have value available. In that managed function, once I have value I am setting the value for the desired textbox. Problem solved.
    • Marked As Answer by bobsov Thursday, April 11, 2013 6:30 AM
    •  
  • Wednesday, April 17, 2013 1:59 AM
    Moderator
     
     

    Hi,

    I am very glad that you have solved your problem by yourself. It will help the others who meet the same issue as you.

    If you have any other problem, welcome to post it in the silverlight forums.

    Best Regards.


    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.