This message is for those of you who are attempting to use adapted controls in combination with ASP.NET AJAX beta 1. In particular, some of you have reported (correctly) that the UpdatePanel is triggering full postbacks rather than partial rendering when it wraps something like an adapted GridView.
I have good news and I have bad news. Which do you want first?
Good news. I have a fix and will try to get it into the next update of the kit.
Bad news. It isn't in the kit at this moment, obviously.
Good news. The fix is something you can implement yourself right now by modifying your adapters.
Bad news. It involves some rather tedious typing. Personally, I did it over a hot cup of coffee and it wasn't too bad. I think it took me about 15 minutes.
Here's the the scoop. ASP.NET AJAX assumes that if there is a control like a GridView on your page (or within an UpdatePanel) then there will be exactly one HTML tag somewhere on the page that has the ClientID of that GridView. In the unadapted situation, there is a <table> whose id attribute equals the GridView's ClientID.
When you use the adapters as they are written right now the GridView is rendered as a <table> and some wrapping <div> tags. None of them is given an id equal to the GridView's ClientID. My initial thinking was naive: nothing needs the ID so why spit it out when it makes the markup look more complex than necessary.
Oooops.
We really do need to put the ClientID of the adapted control onto some tag on the page. That way, dependent tags (like ASP.NET AJAX "extender" tags) can count on being able to find some tag on the page that they can act upon via its unique client id.
It turns out that this will be a relatively simple thing to add to the adapter kit... but it does require a change to the signature of one of the central methods in the kit so we're going to have to update a bunch of calls to that method. Let me explain. (I'm going to provide the code here as C# but the fix ultimately will be implemented in the kit in VB.NET, too, of course.)
First, you need to edit App_Code\Adapters\WebControlAdapterExtender.cs. Locate the method called RenderBeginTag. Change it to look like this:
public void RenderBeginTag(HtmlTextWriter writer, string cssClass)
{
string id = (AdaptedControl != null) ? AdaptedControl.ClientID : "";
if (!String.IsNullOrEmpty(AdaptedControl.Attributes["CssSelectorClass"]))
{
WriteBeginDiv(writer, AdaptedControl.Attributes["CssSelectorClass"], id);
id = "";
}
WriteBeginDiv(writer, cssClass, id);
}
Now find the method WriteBeginDiv (in the same file). Change it to be this:
static public void WriteBeginDiv(HtmlTextWriter writer, string className, string id)
{
writer.WriteLine();
writer.WriteBeginTag("div");
if (!String.IsNullOrEmpty(className))
{
writer.WriteAttribute("class", className);
}
if (!String.IsNullOrEmpty(id))
{
writer.WriteAttribute("id", id);
}
writer.Write(HtmlTextWriter.TagRightChar);
writer.Indent++;
}
Now comes the tedious part. You need to find every other call to WriteBeginDiv that is in the kit. And you need to add an extra argument, final argument, an empty string. The files you need to touch are:
ChangePasswordAdapter.cs
CreateUserWizardAdapter.cs
LoginAdapter.cs
PasswordRecoveryAdapter.cs
WebControlAdapterExtender.cs
So, for example, in ChangePasswordAdapter.cs at line 192, I changed the original call that looked like this:
WebControlAdapterExtender.WriteBeginDiv(writer, className);
to be this:
WebControlAdapterExtender.WriteBeginDiv(writer, className, "");
Notice that I added an new arg to the end of the call's arg list. It is an empty string, signifying that there is no ID to add to the <div>. Right now, we only need to add the main ClientID as the id for an outter tag in whatever the adapter renders.
Clear as mud so far? :)
OK, if you do all that and if you use beta 1 of ASP.NET AJAX I think you'll find that UpdatePanel allows partial rendering of adapted controls. My initial testing shows that to be the case. However, it would be terrific if Ian or others in the community could provide additional feedback on this.
Regards,
Russ Helfand
Groovybits.com