views:

578

answers:

1

Is it possible, with the ASP.NET Ajax library (Sys....) to add controls to the page. For example in JQuery I would perform

$("#mydiv").append($("#anotherdiv input"));

Or something similar. I want to do this without wrapping everything in an UpdatePanel if possible, preferably through clientside scripting. But I have a feeling this will confuse the ViewState.

N.B. This isn't a dupe of this post, which is about something different.

I'm closing this as it is possible, however it's fiddly. Chapter 10 of ASP.NET AJAX in Action covers it a little. Without partial postback though it's impossible

+1  A: 

Your correct--it would confuse the viewstate as all the controls need to be on the page during or before the OnInit() method, as far as I can remember.

Yet, you may still be able to use some jQuery/Ajax to pull back the rendered control. Say, for instance, you had a "helper" page, "MyControlsOutput.aspx", and on that page, you had your control embedded into it, ie "". Then, you could, in theory, use jQuery to query the MyControlsOutput.aspx page, and return the responsetext to your page. Again, it would not be in your ASP.Net page's control collection, nor would it have any clue about your viewstate. So, this is probably not what you're looking for, but, it was just a thought.

...While writing the above, I did a quick Google search for "asp.net ajax load control". See if this may help (you may have already seen this, sorry if that's the case):

http://weblogs.asp.net/sanjeevagarwal/archive/2008/07/22/Dynamically-create-ASP.NET-user-control-using-ASP.NET-Ajax-and-Web-Service.aspx

It's a similar concept, but it looks like they are using ASP.Net's ajax calls, and loading it into the page's control collection, and letting it use the page's viewstate as well. Couldn't hurt, eh? :)

Hope that helps a little bit. Good luck.

Carl