Is it possible to dynamically add webcontrols via jQuery?

Assuming this is indeed ASP. NET WebForms and you do plan to submit (fairly arbitrary) data using a postback, your best bet would probably be to use some sort of client side or server side templating as Raj mentioned Then before the form is submitted, you could use something similar to the approach described here ( Serialize form to JSON with jQuery ), save the dynamically created data into a hidden field, and use a JSON parsing library server side to parse the data and turn it into meaningful objects you can work with If it's at all an option, this kind of stuff is trivial to do using ASP. NET MVC.

You could (fairly easily) splice it into an existing WebForms project and have the two live side by side. The main downside of it is that it will be a bit of a franken-project and people maintaining the project in the future would have some family unfriendly things to say about your design decision.

Assuming this is indeed ASP. NET WebForms and you do plan to submit (fairly arbitrary) data using a postback, your best bet would probably be to use some sort of client side or server side templating as Raj mentioned. Then before the form is submitted, you could use something similar to the approach described here (Serialize form to JSON with jQuery), save the dynamically created data into a hidden field, and use a JSON parsing library server side to parse the data and turn it into meaningful objects you can work with.

If it's at all an option, this kind of stuff is trivial to do using ASP. NET MVC. You could (fairly easily) splice it into an existing WebForms project and have the two live side by side.

The main downside of it is that it will be a bit of a franken-project and people maintaining the project in the future would have some family unfriendly things to say about your design decision.

Yeah, I would love to use mvc for this and you're right in that it would be simple to implement. Unfortunately the constraint you mentioned is spot on in that we have a support team that will need to make heads and tails out of this when i'm done. Thanks for the tip!

– Chris Conway May 29 '10 at 12:33.

Use ViewManager. RenderView demonstrated here: http://weblogs.asp.net/scottgu/archive/2006/10/22/Tip_2F00_Trick_3A00_-Cool-UI-Templating-Technique-to-use-with-ASP.NET-AJAX-for-non_2D00_UpdatePanel-scenarios.aspx Return the contents in a webservice and read with ajax. Update Roman Army, I see what you are saying.

Chris, are you planning on posting back the data from the new content that was added? If so, this will not work. Your best bet is to use the ASP.NET Ajax framework and the UpdatePanel.

The limitation of that approach is that it doesn't update the ViewState so ASP. NET may rebel a little when Chris tries to submit data. You'll notice the demo is about rendering content, not submitting it back.

Since then Microsoft has put a bit of work into client side templating. – R0MANARMY May 29 '10 at 2:40 I'd need to be able get the values of each of these controls on postback. - I'm gonna go with yeah, he's gonna need to post them back =).

– R0MANARMY May 29 '10 at 3:56 yes, I would need access to the data in each of the new controls to persist to the database. I haven't tried it yet, but I'm assuming I should be able to do something like Request"idOfDynamicControl" to get the data server-side. – Chris Conway May 29 '10 at 12:37 @Chris Conway: When you say "control" I assume you mean primitive html inputs, not asp.Net user controls, right?

If so then yes, they should be in the request collection. – R0MANARMY May 29 '10 at 13:45 yeah, I mean just any html control, not the asp.Net control. I like the idea of the serialized json in a hidden input field and then retrieving and parsing on the server side.

Next week i'll give that a try and mark the question as answered when successful. Thanks! – Chris Conway May 29 '107 at 1:15.

What I'd like to be able to do is add a webcontrol's content when one of the links is clicked. Is this kind of thing even possible? If not, what's the best strategy for loading a set of controls (one textbox and one dropdown with values from one link, two textboxes and a checkbox from another link, etc.).

I'd need to be able get the values of each of these controls on postback. Ideally, I'd like to be able to add that new content to an acordian control, most likely the jQuery UI acordian. So each clickable link would add new content to an acordian control.

What's everybody's thoughts on this?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions