Thursday, January 14, 2010

Double postback on ASP.net forms

I have a recent situation where a page_load event is firing multiple times in asp.net (2.0). Sometimes it's twice, sometimes many times.

There are several things that cause this, I've been bitten by two of them.

1) Having two events hooked to the page_load via the Handles clause. Note the Me.load. This appears to be placed sometimes by the IDE.

Private Sub Page_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load <--eek!

2) This one really threw me. Sometimes an Image control with no URL will cause this. Also, links with blank URLS can also cause this. When diagnosing, substitute in as needed.

No comments:

Post a Comment