ASP.NET


Hunch: If you embed a HTML control (like a hidden field) in a Template column in a DataGrid or DataList control, you must add the runat=”server” attribute to the control or else the FindControl method on the Item object for that row will return nothing.

Bogus!  OK, ASP.NET throws an exception if you try to reference the Page.IsValid property before either calling Page.Validate() or posting back based on a control that has a “CausesValidation” property of true.  The problem is that you can set AutoPostBack to True on drop-down lists, but it DOESN'T HAVE A CAUSESVALIDATION PROPERTY!  Why not??  So, if you are letting your drop-down listboxes cause a postback, be sure to call Page.Validate() before checking the IsValid property.

You can specify a Reply To address in an SMTP message by adding the Reply-To header with an address in the format:

“Display Name” <actualaddress@site.com&gt;

Use .Headers.Add(”Reply-To”, addressinformation) to add the correct header.

The Dispose method on a WebControl/Page can be overriden to handle closing of connections, etc. when the page request is done.

For an object inherited from System.Web.UI.Control, the Load event happens before any postback events are processed.  This means that you cannot expect a button click or other similar event to hit before a Page_Load on an ASP.NET page.

It appears that the PreRender event on a System.Web.UI.Control object is the last place you can make anychanges to a control's contents and have it persisted to the viewstate when the page is rendered.

You can “upcast” (my term for treating a base class type as an inherited class type) the EventArgs in a method like OnBubbleEvent by checking the e argument (of type System.EventArgs) using the TypeOf keyword in Visual Basic.NET or the is keyword in C#.  More on this later.