Getting data out of a Silverlight control - c#

I am relatively new to Silverlight development and I am trying to figure out how to get data out of a silverlight control that I have made.
I have a Silverlight control that gathers a bunch of graphical data points. The Silverlight control is embedding in a asp.net webforms application. The page that is displaying the control also does other data specific functions and when the user clicks a button I need to perform some manipulation of the data (both webform data and the data contained in the Silverlight control) and then save the data with 1 call to the DB.
My question is how do I get the data out of the Silverlight control from my webform to be able to put the data together for the save?
My initial thought was to make the data in the Silverlight control accessible via Javascript and then on the button click, save the Silverlight control's data to some html control and then allow the regular webform post to occur and read the data server side. Is there a better way to do this as it feels a little messy.
Note: I am using .NET 3.5 and Silverlight 3.0.

You have a lot of options:
You can have your Silverlight control submit the data directly to the server, using ADO.NET Data Services or a webservice call which processes the data
You can use RIA Services, which simplifies the process of interacting with server-side code from Silverlight
You can have the Silverlight control update a form field (hidden, probably) which then can be processed and submitted via the web page

Marc Gravell's protobuf-net library for silverlight may be an option for server side comms. Googles protocol buffers can comunucate with lots of lauguages.

Related

Transferring an existing C# and ASP.NET Web Form site to Bootstrap

So I have an existing page that's running ASP.NET and C# in order to display a front-end for some PowerShell commands. This was all developed in the community/free version of Visual Studio 2017.
Pseudo-code is below
User browses to page in browser
Browser presents lists of buttons and text fields
User inputs options into fields and clicks a button
C# runs in backend to run a PowerShell command doing various things, dumping into a JSON file the results
C# returns the results to the page by reading the JSON and turning it into a C# object, displaying as a C# Table
What I have already is that page (and sub pages for different features), displaying results to a simple table or div and displaying the buttons and text fields using the default C# table and some custom HTML to display the JSON properly.
What I want though, is to be able to port those features and functions to a Boostrap template, so I can take advantage of the handy dropdown menus, fancy buttons, etc. that are provided by Boostrap. Specifically I'm looking at using Flatkit.
All of the examples I've seen have either been for MVC stuff, starts entirely from scratch, or uses very simplistic Hello World examples, neither of which help when tackling this task as my code is web form based and more complex than an About page.
So my question(s) is/are
a) How can I create ASP.NET controls that will both play nicely with Bootstrap and feed data back into the C# file for processing? Something that can duplicate an <asp:Button> essentially, without refreshing the page entirely.
b) How can I then create another control or similar element on the front-end side to display that information? I'm using a simple <asp:Table> currently
I have the backend PowerShell and most of the logic written, I just need to know how I can make it interact nicely with Bootstrap essentially.
Web dev is not my usual forte , so a lot of the tutorials feel like reading Ancient Greek as they assume I know JQuery, Angular, DOM, etc. So if there's knowledge I'm lacking to make this work, links would be great.
Thanks!
End of day, Bootstrap or any CSS framework applies styles to HTML elements. ASP.Net Web Forms Controls render "vanilla" HTML - though some can be unwieldy (like <form> input name and id attributes - re: ASP.net uses the same value).
They can be styled as needed. Look into CssClass
Hth.

Silverlight / WPF communication

I have a WebBrowser control showing a Silverlight application. This control is in a WPF application. Obviously this is a bit of a hack to integrate Silverlight with WPF as ultimately neither one knows about each other, they're completely independent.
So what I need is for Silverlight to post a value into the WPF application. What I was thinking was using JavaScript hosted in the .aspx page in the Silverlight application which can be accessed from both Silverlight and WPF. I think it is fairly simple getting data from Silverlight to the .aspx page but I'm not sure how to get the data from the .aspx page to WPF. Ideally I don't want WPF to have to call for the data, I want it to be posted from Silverlight and appear in the WPF application without WPF having to do anything except receive and display the data.
Hmm...hope that makes sense.
Silverlight to/from JavaScript: see here
MSDN - Making Silverlight Scriptable by JavaScript
WPF to/from JavaScript: see here
Stack Overflow - Invoke C# code from JavaScript in a Document in a WebBrowser
Code project - Working with webbrowser in wpf

Refreshing webform when database is externally updated

For experimental purposes i've made a ASP.net webform that writes to a database. Ive also made a windows form(c#) that writes to the same database.
The webform displays the text in a gridview and the winform displays the text in a datagridview.
My question is: is it possible to refresh the windows form and webform when the database is updated by the other? And if so, could anyone point me in the right direction?
George has suggested one good approach in his comment.
For ASP.Net, you could use SignalR to update the web page.
ASP.NET SignalR is a new library for ASP.NET developers that simplifies the process of adding real-time web functionality to your applications. Real-time web functionality is the ability to have server-side code push content to connected clients instantly as it becomes available.
The traditional approach would involve "polling" by the desktop app, that is, making a request every few seconds to see if there is new information. This approach can be resource-intense. You can also do polling from a web page, of course.
The simplest way to do this to use two timer controls, one in the WinForm and the other on the WebForm.
And at desired intervals just rebind the dataset.
Rebind Data
grdWaiver.DataSource = dv 'Set the dataview to the DataGrid
grdWaiver.DataBind()
(In above I used a dataview as a datasource)

Using ASP.Net Web Databound Controls to create Jquery Sliders tickers type controls

I am working on a B2B portal web app, where i need to display upcoming news , products and company info on regular interval (say as slideshows and tickers).
For example :
Scenario 1. I need to display the latest company(registered in this week) in a marquee style. Where companies will be pulled out from database.
Scenario 2: I have some products categorized as hot products, that will be displayed as slideshow on the home or somewhere else.
I know using Jquery and Static pages its possible. But i havent idea about how to do this with ASP.Net databaound controls like grid, repeaters, datalist etc. We are not in favour of purchasing third party controls, instead it will be a last resort for us.
Please help me through buil-in controls. Any help will be highly appreciated.
You should decide whether you want to do with JQuery Widgets or ASP.NET controls (or third party ASP.NET controls like Telerik). Can you use both - yes you can, but you are only going to add more complexity to your app because ASP.NET controls don't know about your JQuery Widgets and you have to provide the glue to tied them both and keep them synched up. So if you decide to build everything in JQuery - convert your static html pages to .aspx pages then add additional serverside functionality to return the data. For AJAX behavior, you can use what is called Page Methods in ASP.NET or write seperate Script Services. You will make use of what is called a ScriptManager. That way you can keep your existing markup and rely on ASP.NET to provide you with Data. The other alternative is to convert everything to ASP.NET Controls - and rely on the builtin or third-party control suite to provide the functionality.

Can ASP.NET Page use WPF Controls?

I was wondering if ASPX page can use WPF Controls (from the toolbox in the designer)?
Because I have a custom user control that I made for a application before but now i am creating a web app. In the web app the controls were grayed out.
I was wondering if there is a way to use the user control in the web app?
Unfortunately, you'll have to create a new ASP.Net control that mimics your WPF control. The two technologies have completely different approaches to rendering (DirectX primitives vs. HTML), events (Routed events vs. Postbacks), etc. and are simply not compatible.
That being said, converting a WPF control to a Silverlight control is doable, and would allow you to leverage your previous work. You would still need to run it through a Silverlight app, though, rather than directly through the ASPX page.
ASP.NET is primarily a server side framework and WPF applications run on the client, therefore they don't really work well together. You might find it easier to convert the WPF control into a Silverlight control instead and pass that through your ASP.NET page. Users will need a Silverlight plugin to run it.
These two posts might help in the conversion:
Porting from WPF to Silverlight: The Missing Pieces, Part 1
Porting from WPF to Silverlight: The Missing Pieces, Part 2

Categories