开发者

Is it possible to dynamically add webcontrols via jQuery?

Currently I have a webform that has a series of links. 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 aco开发者_JAVA百科rdian. So each clickable link would add new content to an acordian control.

What's everybody's thoughts on this?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜