freefaller
freefaller

Reputation: 19963

Loading UserControl via AJAX, and posting back to the server

Summary

Is it possible to dynamically download the contents of a UserControl via AJAX, insert that into the HTML, post-back the page to the server and for the server to be able to process the dynamically loaded controls?

In particular I'm looking at doing this multiple times, to create the ability to "add rows" to an existing table structure in the page.

More Detail

I have already written ASP.NET code that successfully downloads the contents of a UserControl via AJAX using the <asp:ScriptManager>, and for that new downloaded HTML to be placed into the current document in the correct position.

This is fine, because all saving of data takes also takes place via AJAX, so it's simple for me to build the data to return to the server.

Part of the problem is that if the UserControl had been loaded as part of the original page, the controls within it would have been given UniqueId along the lines of...

ctl100$container$repeater$ctl100$myTextBox

But when loaded outside of the structure via the AJAX route, it is given a UniqueId along the lines of...

ctl100$myTextBox

... with the result that (obviously) the server doesn't know what to do with it.

So what I'm looking to do is be able to download dynamically a usercontrol, and be able to post that back as part of the page.

What is the standard approach to achieving this?

Upvotes: 2

Views: 249

Answers (1)

IUnknown
IUnknown

Reputation: 22478

The standard ASP.NET Web Forms approach is using of UpdatePanel control. There are a lot of functionality like controls state maintaining, events handling, request validation that requires that server controls must be rendered and added to page's control's tree on postback.

Upvotes: 1

Related Questions