views:

39

answers:

4

Hello

Can I dynamically create controls in Silverlight without a postback to the server (even an asynchronous one). Does silverlight drag-n-drop requires postback?

I'm asking this because I've an asp.net application where I dynamically create/delete lots of controls. So after the postback I'm getting error with view state stating that the control tree doesn't match the view state tree.

Can I avoid such problems in Silverlight?

A: 

Yes you can add controls dynamically to pages, without a round-trip to the server.

Drag-drop is also executed client-side.

Think of Silverlight as more like a desktop app, that talks to the server only to get/save data.

Adding controls dynamically in Silverlight is as simple as newing the appropriate control class and inserting it in the render tree (e.g. by adding it to a parent control).

Enough already
+1  A: 

everything done in a silverlight control/application happen on the client. web service calls if any happen asynchronously. thats on of the advantages of using silverlight

Vinay B R
+1  A: 

The vast majority of what goes on in Silverlight involves no postback. In fact, I'd say Silverlight represents a completely different mindset. Whenever there IS a postback from Silverlight, it will almost always be asynchronous, and there is no "view state" that the server needs to worry about. In my opinion, it makes ASP.NET look like a joke when it comes to writing web applications.

Eric Mickelsen
+1  A: 

Here is an example: http://asd.murven.com/blog/post/2009/10/16/Silverlight-Adding-controls-dynamically.aspx.

However, I would not suggest switching to Silverlight just to kill this bug. Only if you have a real need for a client-like application instead of a real web application. ASP.NET is suitable for dynamically creating controls as well. Please remember to initialize the control on the server during each postback. If this doesn't help, I would suggest you to submit a description of your problem with some code to help us solve it with you.

Br. Morten

Maate