12 December 2006

AJAX and .Net

Recently I've been having trouble 'enabling' AJAX on an existing website. It took me days to figure out the actual cause of the problem. The website was recently upgraded to Framework 2.0...
I added an UpdatePanel to the user-control and it wasn't working... gave an error The UpdatePanel '<controlid>' was not present when the page's InitComplete event was raised. Googled and told I was using older version of ASP.Net AJAX which wasnt the case.

Later colleague who did the actual conversion told me his version is working, got his version and tested on mine and tried to apply same principles but no luck.
Tried removing UpdatePanel from user-control and loaded dynamically, got a different problem... It was post-backing.

The sample from net was working though but it also had a problem when I moved UpdatePanel to user-control (together with ScriptManager).

I seems like sometimes a user-control must be loaded dynamically for AJAX to work.

What the actual problem was the table to which the UpdatePanel was loaded. UpdatePanel must not be inside a table. When I removed the table, it worked.

Here's is the HTML from the containing page:


Notice that the UpdatePanel is outside the table.

In code (c#) you need the ff lines:

string CTRL = LoadControl("/~Templates/SelectProducts.ascx");
UpdatePanel1.ContentTemplateContainer.Controls.Add(CTRL);


Notice that the user-control was NOT added to the Update panel itself but to the ContentTemplate container.

No comments: