Replacing embedded Silverlight UserControl

bmcguire
Posts: 4
Joined: Wed May 11, 2016 10:23 am

Replacing embedded Silverlight UserControl

Postby bmcguire » Wed May 11, 2016 10:36 am

Hello.

I am wondering if it is possible to add an XAML User Control to an existing aspx project, rather than creating a seperate project specifically for the CSHTML5 User Control?

For background, I have been tasked with replacing an existing Silverlight User Control that is embedded in an aspx page as an object (shown below

Code: Select all

<object
    id="objImageViewer"
    data="data:application/x-silverlight-2,"
    type="application/x-silverlight-2"
    width="100%"
    height="524px">


If it is possible, which References to I need to include.

Thanks,

Bruce.

JS-Support
Site Admin
Posts: 664
Joined: Tue Apr 08, 2014 3:42 pm

Re: Replacing embedded Silverlight UserControl

Postby JS-Support » Thu May 12, 2016 12:19 pm

Dear Bruce,

The CSHTML5 project structure works very similar as the Silverlight project structure:
• In Silverlight, you need a separate Silverlight project to build the XAP file that you will then embedded into your ASPX page.
• In CSHTML5 it is the same: you need a separate CSHTML5 project to build the HTML/JS files that you will then embed into your ASPX page.

To do so, that is, to embed the output of your CSHTML5 project into your ASPX file, do the following:
1. Copy the files that are in the bin/Debug/Output subfolder of your CSHTML5 project folder => into a new folder inside the project that contains your ASPX file.
2. Then, in your ASPX file, create a new <iframe> that points to the files that you copied (more specifically, to the "index.html" file that you copied).

Please feel free to let me know if something is not very clear.

Regards,
JS-Support

bmcguire
Posts: 4
Joined: Wed May 11, 2016 10:23 am

Re: Replacing embedded Silverlight UserControl

Postby bmcguire » Mon May 16, 2016 1:24 pm

Good afternoon.

Thanks very much for the information.

Is there a recommended method for passing information into the generated HTML5 frame?

HttpContext.Current.Session was the method I was using previously, but I am not sure if the iframe will be able to get the same session objects.

Thanks,

Bruce.

JS-Support
Site Admin
Posts: 664
Joined: Tue Apr 08, 2014 3:42 pm

Re: Replacing embedded Silverlight UserControl

Postby JS-Support » Tue May 17, 2016 6:24 am

Dear Bruce,

It is not specific to CSHTML5. You can pass simple values by adding them to the URL of the frame (in the "query string"), and then read them with the following code inside your CSHTML5 project:

Code: Select all

string url = Interop.ExecuteJavaScript("window.location.href");


Alternatively, the content of the iFrame can call methods defined in the host page in order to retrieve information. To do so, use the "window.parent" JavaScript code which gives you access to the "window" object of the host page, as shown here:

Code: Select all

Interop.ExecuteJavaScript("window.parent.MyMethodDefinedInTheParentWindowObject()");


where you must replace "MyMethodDefinedInTheParentWindowObject" with a method you define in the host page.

Regards
JS-Support


Return to “General Discussion and Other”

Who is online

Users browsing this forum: No registered users and 1 guest