Hanselman’s Interview: Postbacks

Explain how PostBacks work, on both the client-side and server-side. How do I chain my own JavaScript into the client side without losing PostBack functionality?

From StackOverflow: Postbacks are an abstraction on top of web protocols which emulate stateful behavior over a stateless protocol. On the client side, postbacks are achieved by javascript calls and hidden fields which store the state of all controls on the page. The server side goes through a life cycle of events, port of that life cycle is the hydration of the viewstate to maintain the state of all controls on the page, and the raising of events based on the parameters that were passed into the __doPostBack call on the client side.

Depending on your requirements, you can use control events like OnClientClick to chain in your client side JavaScript, or you can use the GetPostBackEventReference method to give your scripts access to the postback method on the client side.

Hanselman’s Interview: Datagrid Binding Events

What events fire when binding data to a data grid? What are they good for?

The unique events that fire during data binding on a datagrid are itemcreated and itemdatabound. They can be used to modify the components of a grid row programmatically. Use itemcreated unless you need access to the bound data, in which case you’d use itemdatabound.

Hanselman’s Interview: Custom File Extensions

What is needed to configure a new extension for use in ASP.NET? For example, what if I wanted my system to serve ASPX files with a *.jsp extension?

The full answer is here, but the short version is that you need to configure IIS to use aspnet_isapi.dll for the file extension you want, then configure web.config to present and compile pages with that extension.

Hanselman’s Interview: HTTP Handlers

What are ASHX files?  What are HttpHandlers?  Where can they be configured?

An .ashx file is a placeholder for an HttpHandler. It allows you to create a IHttpHandler implementation as simply as you create a .aspx file, without any reconfiguration of web.config or other hoops. It provides you access to the Request and Responsie without any of the facilities or overhead of the page model.

HttpHandlers are low level implementations of the request/response http cycle. Using an HttpHandler, you can deliver responses back to the browser with minimal overhead. A good example of this would be a dynamic image generator that could be accessed using the <img> tag.

You configure HttpHandlers by registering them in web.config. You may also need to configure IIS to send certain file extension requests to aspnet_isapi.dll.

Hanselman’s Interview: ASP.NET Lifecyle

From constructor to destructor (taking into consideration Dispose() and the concept of non-deterministic finalization), what the are events fired as part of the ASP.NET System.Web.UI.Page lifecycle. Why are they important? What interesting things can you do at each?

  • Object Initialization (Server object and page object instantiated)
  • PreInit (Add dynamic controls)
  • Init (Change control initialization values after control init)
  • InitComplete (All controls initialized)
  • PreLoad (Before stat loads)
  • Load (State has been loaded) (Page called first, then controls)
  • Control Events (Events caused by postback)
  • LoadComplete (Post post-back processing)
  • PreRender (last changes to viewstate)
  • SaveStateComplete (post-viewstate processing)
  • Render (generate html)
  • UnLoad (cleanup)
  • Dispose (objects destroyed)

You must RELEARN what you have learned.

Caught out again.

I pride myself on limiting myself to actionable worries. I read things that I have a purpose to read. I do things that have a purpose to do. I was listening to Rob Walling’s Micropreneur Academy lessons today and got a strong reminder not to waste time with un-actionable things. I need to go prune my RSS reader and delete a bunch of worthless podcasts. I want to learn everything, but not everything has value.