MS AJAX Beta1 - ClientScript is dead, long live ScriptManager

Posted by: the telerik blogs, on 23 Oct 2006 | View original | Bookmarked: 0 time(s)

As some of us have found the latest installment of MS AJAX is not backwards compatible. Shortly after ScottGus 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 developers 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 (dont 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.

Advertisement
Category: ASP.NET | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 5138 | Hits: 48

Similar Posts

  • UpdatePanels and ClientScript in custom Controls more
  • New Best Practice: Ajaxifying UserControls more
  • 2009 Predictions - ASP.NET, BizTalk and LINQ 2 SQL are dead and so are VB, C# and Azure more
  • An update to the ClientScriptProxy Class for ScriptManager/ClientScript more
  • UpdatePanels and ClientScript in custom Controls more
  • Why OpenAccess does require transactions? more
  • An update to the ClientScriptProxy Class for ScriptManager/ClientScript more
  • What is Scalability? Do I have Extreme Requirements? more
  • Windows Server 2008 + SQL Server 2008: Really better together. more
  • SLEEPLESS ROADSHOW The Ultimate Office Dev Weekend more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD