MS AJAX Beta1 - ClientScript is dead, long live ScriptManager

by ASP.NET AJAX Team | Comments 5

As some of us have found the latest installment of MS AJAX is not backwards compatible. Shortly after ScottGu’s official statement our QA team reported that none of our controls worked with MS AJAX Beta 1. That is really bad news if you happen to claim to be the first ASP.NET component vendor with official ATLAS support. This called for a desperate debugging session which happens to be what I and Hristo Deshev like the most :). So I downloaded and installed the latest version (kudos to Microsoft for the painless install). I created an “Ajax enabled web site” and wired up r.a.d.input. Indeed our control died after being updated by the UpdatePanel – the JavaScript object representing it was never initialized. I used FireBug to see that the init script was not emitted after the update. We used Page.ClientScript.RegisterStartupScript to emit that init script and it used to work like a charm in the April ATLAS CTP. I felt that I lack some ATLAS/AJAX knowledge and summoned Hristo Deshev. It turned out to be a very good idea (pair programming really works). First we tried to find the answer in google – no luck (actually there was a comment by ScottGu but we found it later). Then we used every .NET developer’s swiss army knife – Reflector. That sacred tool showed us that we should start using Microsoft.Web.UI.ScriptManager.Register* instead of Page.ClientScript.Register*. We did a quick test and r.a.d.input was back in the game. The real challenge is calling those methods without dragging in a reference to MS AJAX's assemblies and without forcing each and every one of our customers to do exactly that. We don't want to have a separate build of our suite and confuse our customers either. We could have added a set of build flags and could have branched the entire suite, so that it has two separate versions: with and without MS AJAX support. That would have been really confusing and error prone to many people. We decided to use reflection instead (don’t worry, it works in Medium Trust :)). For example here is how to get the current script manager (still no reflection here):

private object GetScriptManager()
{
   foreach (DictionaryEntry entry in Page.Items)
   {
      if (entry.Key.ToString().IndexOf("Microsoft.Web.UI.ScriptManager") >= 0)
      {
           return entry.Value;
      }
   }
   throw new ArgumentException("...");
}

Then calling the RegisterStartupScript method (as well as a few others) was a piece of cake. We used reflection to call those methods it worked.

Luckily all MS AJAX related code lives in a base class so those changes will be picked up by all controls.

We will do our best to release a new service pack addressing MS AJAX Compatibility issues next Monday. Have in mind that the service pack release will no longer support older versions of ATLAS.

About the author

Stefan Rahnev

Stefan Rahnev

is the Unit Manager of the ASP.NET Telerik Division. He has been working for the company since 2005, when he started out as a regular support officer. His next steps at Telerik took him through the positions of Technical Support Director and co-team leader in one of the ASP.NET AJAX teams. Stefan’s main interests are web development, agile processes planning and management, client services and psychology.

5 Comments

Todd Anglin
Great debugging work! I'm glad you found the solution so quickly. This quick response to Beta 1 should keep you on top of the pack as far as "Atlas" support goes. I downloaded Beta 1 last night and look forward to seeing how it integrates with the service pack next week.
Atanas Korchev
Hi Steve,
Thank you for the link. Unfortunately refering to the MS AJAX assembly is not an option for us right now and we will stick to the less elegant solution posted above (getting current ScriptManager).
Eilon (Microsoft)
Please see these two articles I wrote recently on the subject:

- What's up with UpdatePanels and how come nothing works? (http://forums.asp.net/thread/1440058.aspx)
This is a higher level piece that explains how UpdatePanel changed from being automatic (and broken) in the CTP to the new functionality in the beta.
- HOWTO: Write controls compatible with UpdatePanel without linking to the ASP.NET AJAX DLL (http://forums.asp.net/thread/1445844.aspx)
This article goes in depth on how to use the new registration APIs on ScriptManager, but without linking to the Atlas assembly.
I'm not sure exactly what "mpe" is but it will have to be inside the UpdatePanel as well if it is going to execute some of its own JavaScript code.

Thanks,
Eilon
Atanas Korchev
Hi Eilon,

Thanks for the nice articles. I read them and I think we ended up with a similar approach to the one described by you. The only one thing which is different is the way we get the instance of the ScriptManager - you get it by type using the fully qualified name; we traverse Page.Items instead. Do you thing we should change our approach? Are there any side effects?
I noticed that your code relies on the version of the ajax assembly (used in the fully qualified type name) - is there any way to avoid that?.

Comments

  1.    
      
      
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)
Read more articles by ASP.NET AJAX Team - or - read latest articles in Developer Tools