views:

282

answers:

9

I never worked with Silverlight before, but I have the requirement to build a fairly dynamic/interactive form to fill out. That leaves me the choice between two technologies I have not much experience with: JavaScript/jQuery or Silverlight. (edit: The application is internal, I can safely assume Silverlight to be available)

At the end, I need to submit some data back to the server. I know that with a normal HTTP Form in ASP.net I can have a Button and an onClick Event - standard stuff. The JavaScript approach would include some DOM Manipulation to dynamically add/remove fields, but when I click on the button the current DOM gets served to my ASP.net Application and I process as normal. It is still a normal WebForms application.

But how would the interaction work with Silverlight? Can I have a Button in a Silverlight Application that essentially POSTs an HTTP Form? Or would I use a Web Service for this? It would be great if the Silverlight Application can get some data back from the server, so I guess it's a web service then?

+1  A: 

Yes you can have button in Silverlight application which will go to server like ASP.net Form. It is same model only we can take advantage of .net framework elements with Silverlight (though in limited manner).

TheVillageIdiot
+2  A: 

It sounds as if you're seeking a web service with Silverlight. The framework is relatively robust and easy to implement - once you dive in it should be no problem to get your web service up and running quickly.

http://silverlight.net/getstarted/

While you could have your Silverlight app post the HTTP form that surrounds it, you need to make sure that this is the proper implementation path for your problem.

JustLoren
+1  A: 

I cant believe everyone is supporting your Silverlight suggestion so far. Use jquery instead! You can create a pretty dynamic form and be guaranteed that you will have access to users across various platforms. I am a web developer and I dont have the Silverlight runtime installed. I strongly suggest jQuery!

Pasta
I should have added: I can safely assume that Silverlight is installed. It's more about me finding out which unknown technology I should pursue, and I lean towards Silverlight simply because I am an existing C# dev.
Michael Stum
+1  A: 

Silverlight is a powerful tool but depending on the level of dynamism required, the path of least resistance might be to just create a ASP.NET page and make it more dynamic using jQuery.

If you use jQuery, you will be learning Javascript and the jQuery library. If you use Silverlight, you will be learning WPF, WCF, and their interaction with .NET server code.

If you already build sites in ASP.NET, you are 80% there with the jQuery route. If you go the Silverlight route, I think the learning curve will be steeper.

If you do go ahead with the Silverlight option, Tim Heuer has some examples of communicating from Silverlight to Asp.net web services.

Timothy Lee Russell
+2  A: 

I dont know how to write any JQuery but I do know Silverlight. I would say that if all you wanted was a form Silverlight would be a little overkill and you might do better with something like JQuery.

However, since you know C# it might be better to go with somthing closer to what you know in order to save time. If I was going to write it, I would go with Silverlight, an ADO.Net Entity Model, and RIA services. Using the Silverlight Dataform you could have a pretty dynamic form up very quick and you could even have simple validation to keep your data clean.

check here for Brad Abrams posts on this.

johnnywhoop
+1 for RIA Services - he can have that form built in no time.
James Cadd
+1  A: 

Hi Michael,

Given your project is internal AND given you can insure that Silverlight is installed AND given that all your choices can deliver what you want, then the answer would seem to be preference or itch (what you personally want to play with).

You didn't give a project deadline. With Silverlight, if you want an RIA designer-like result you're very likely going to need Blend (which you didn't mention if you had access), further you'll then have to spend a bit of time learning how to use Blend (how much effort depends on how rich your RIA needs).

The break down as I see it:

Webservices: If you're starting fresh you should use RIA or WCF unless you have a good reason to use a webservice (like it already exists, you have no choice, etcetera).

WCF: Replaces webservices, however, you will often have to build much of the plumbing yourself.

RIA: Targeted to implement data services for Silverlight (expected to be expanded to include ASPX in the future). RIA Services is not quite yet in beta. You should keep in mind that there may be breaking changes and would the app not working until you can address those changes impact your company overly?

You've left out ASPX without giving your reasons. This may be that your idea of dynamic is different than many. I have to wonder if ASPX and AJAX (assuming you even need AJAX) wouldn't solve your issue best.

jQuery can certainly do the job, so the ball is in your court. How much time do you have and what do you want to learn and how dynamic do you really want/need to be?

Addressing some of the other points in this tread. Silverlight learning doesn't have to be that steep. If you're not learning animation, then the Blend IDE is likely the most time consuming part. In fact, if you're mostly using VS to code in then Blend would be primarily used for layout. For simple RIA you could even skip Blend (but I wouldn't reccomend doing so).

Lastly, you might consider working on some specs (behavior/design/DB) and then asking what people would use.

+2  A: 

Here's a way you can do it via Silverlight if you wanted to do a form post from a button click.

In your aspx page that hosts the Silverlight control add a div, in my example I called it formDiv. The variable formData is your form that you've created to post.

        var doc = HtmlPage.Document;
        var el = doc.GetElementById("formDiv");
        el.SetProperty("innerHTML", formData);
        try
        {
            el.Children[0].Invoke("submit");
        }
        catch (Exception)
        {
            throw new LogicException("Error launching post");
        }
mstrickland
+1  A: 

In a nutshell, it uses web services via a Silverlight WCF client implementation, and Silverlight offers a few ways to access web services.

  1. Here's a quick how-to on Adding a simple Silverlight-Enabled WCF service to your website

  2. And a comparison to plain ASMX services

  3. The 'Hot' new thing is .net RIA services, here's a tutorial you should also check out Brad Abram's blog, he has lots of info about it.

The silverlight.net videos are great as well, there's several examples.

TJB
+2  A: 

I suggest that you try out Silverlight to get a feel for how powerful that environment is. Personally I think that jQuery is nice, but you get a much more controlled and rich environment if you use Silverlight.

  1. Assuming you are using Visual Studio 2008 download Microsoft® Silverlight™ 3 Tools for Visual Studio 2008 SP1. This will enable you to create Silverlight projects in Visual Studio. You can also use Expression Blend to author Silverlight applications, but as long as you are comfortable writing XAML without a visual designer you might find Visual Studio a bit more mature from a developer standpoint.
  2. If you want to you can try Microsoft .NET RIA Services July 2009 Preview. It is a very powerful environment enabling your Silverlight application to seamlessly work with your data-model on your ASP.NET server. In particular there is very good integration with LINQ to SQL and the ADO.NET Entity Framework. However, if you are new to Silverlight you might find the learning curve a bit steep. You will have to load query operations in order to execute them asynchronously etc. Have a look at the Word document found at the download location to get you started.
  3. As others have suggested you can simply hide an HTML form in the web page hosting the Silverlight control and then use the HtmlPage object from within Silverlight to access the browser DOM to submit your form.
  4. If you want to do POST operations from within Silverlight without using a web service framework like .NET RIA Services or WCF you can use a WebClient or HttpWebRequest object. Silverlight 3 has two HTTP stacks and the default is to use the browser stack ensuring that browser cookies (e.g. forms authentication cookies) are used in your request.
  5. Your form has a complex interaction logic and I strongly suggest that you have a look at the MVVM pattern. In Silverlight you create a view-model containing all relevant data for the form. Relevant data not only include the values of the fields in the form but also information about which controls are enabled, selection information if that applies etc. You then data-bind the form (view) to the view-model and by implementing INotifyPropertyChanged in the view-model you get a complex interaction logic if not for free at least in a way that is reasonable easy to handle as a developer. The partial client-side classes generated for you in .NET RIA Services are particular good candidates for view-models making it straightforward to apply the MVVM pattern within that framework.
Martin Liversage
All answers are good and helpful and I encourage to read them all. I am accepting this because it answered the question best for _me_, but YMMV.
Michael Stum