In the Previous post we accessed the public method inside the SIlverlight module from an .aspx page ,In this we are doing vice versa.
As per our objective we have a control inside a master page of a sharepoint site and a Silverlight control is hosted inside the webpart of a sharepoint page.So we need to access the sharepoint control when we click any button inside the Silverlight module through javascript.
So here are objective is to first access the control and then append a span tag to display some text inside the control on click of some button inside Silverlight control.
Followed Approach:
· Go to the Page load event and include the below code snippet
--------------------------------------------------------------------------------------
HtmlPage.RegisterScriptableObject("page", this);
HtmlDocument doc = HtmlPage.Document;
strControlInnerHTMLGlobal = doc.GetElementById("SharepointControlID").GetProperty("innerHTML");
strControlInnerHTML = strControlInnerHTMLGlobal + "<span >></span><span >Added in Sharepoint control through Silverlight button click </span>";
doc.GetElementById("SharepointControlID").SetProperty("innerHTML", strControlInnerHTML);
--------------------------------------------------------------------------------------
In above code snippet "SharepointControlID” is the ClientId of sharepoint control.
We are taking the object of control through its ClientId and then getting the innerHTML of the control which is in the form ‘span’ tags, and then we are appending the required span tag in the control.
Note: Here we are using GetProperty and SetProperty method through which we get the innerHTML of the control and then we can change the value as per our requirement.
Happy Coding J
No comments:
Post a Comment