Archive

Archive for the ‘ASP.Net’ Category

Atlas – AJAX Programming for the .NET 2.0 Framework

May 19, 2006 Leave a comment
I just completed a webinar on using Microsoft’s Atlas framework for creating "AJAX" applications in ASP.NET 2.0.  Despite that one of my demos failed to work (my poor, poor typing skills) the webinar went well.
 
The webinar started with an introduction to AJAX with a little (read: cheesy) demo of AJAX using a text editor and a browser.  The presentation moved into an overview of the Atlas framework and a decription of the client- and server-side architectures and improvements.  Of course, this all included some more cheesy demos (yet representitive) of:
  • Client-Side O-O API
  • Client-Side Declarative XML
  • Server-Side Control Extenders
  • Server-Side Partial Rendering (UpdatePanel)

For anyone that wants them … here are links to my slides and code:

For more information I recommend you check out the Atlas home page at: http://atlas.asp.net .

Categories: ASP.Net

Events not firing for controls in the HeaderTemplate of a Repeater

October 6, 2005 Leave a comment
Problem
At a client’s site, we were making extensive use of Repeater controls to render data piped to it via a custom entity and collection.  In addition, we wanted to implement sorting in the repeater using LinkButtons which were rendered in the HeaderTemplate of the Repeater.  So for so good … seems like a pretty reasonable request and it works. 
 
In addition to this, we also hosted these Repeaters (amongst other UI elements) in a UserControl so that we could take advantage of the WYSIWYG design features of Visual Studio.Net.  These UserControls, in turn, were to be re-used in several aspects: hosted on ASP.Net web pages, loaded dynamically into server controls, and loaded dynamically into SharePoint WebParts.  The last was the most important as prior to ASP.Net 2.0 there are no easy WYSIWYG methods for creating WebParts so we decided to host UserControls inside WebParts.
 
At this point, the UserControls worked just fine when hosted on an ASP.Net web page leading us believe everything was ok.  We dropped the user controls onto the test web page and used the Page_Load event to pass data into the control to be rendered.  The LinkButtons that were in the header of the Repeaters re-sorted the data and everything looked great.
 
Next came the WebParts
At this point we created WebParts that were designed to host the UserControls and pass along any personalization and configuration properties from SharePoint’s Storage to the UserControl.  Again, everything appeared to be working great with one exception: The LinkButtons were no longer sorting!  I figured it had something to do with the fact that I was lazy and did all of my work in the RenderWebPart method (no need to lecture me; I have learned my lesson).  I moved the call to Page.LoadControl to the CreateChildControls() method where it should have been the entire time.  This would assure that the UserControls were created and added to the Page’s collection in time for the events to fire.  Almost there….
 
Still … the events did not fire but I still had a little bit of laziness left in me.  My thoughts went back to when I gave SharePoint WebPart development training.  In my own words were: "You should create the controls in CreateChildControls, load them in the Load event of that control, and ONLY render them in RenderWebParts."  Of course, there is a reason for this which I now realize. 
 
In a Repeater control, the HeaderTemplate (and FooterTemplate) is not created until the DataBind event is called and, thus, any controls in the template will not exist until that happens.  In my laziness I had not moved the actual loading of the data in the UserControl out of the RenderWebPart method so while the control itself was getting added to the controls collection at the correct time, the LinkButtons did not exist.  Following my own advice I moved the loading code into the UserControl’s Load event (on the web part) and now everything works as advertised.
 
The Moral
Having passed my ASP.Net MCP … I should have known better.  Having uttered the words in training that would have prevented this from being a problem in the first place … I should have known better.  Being lazy at the wrong time … priceless.
Categories: ASP.Net
Follow

Get every new post delivered to your Inbox.

Join 99 other followers