Friday, December 12, 2008

Page Loading Twice! or Data Binding Twice!

I often run into the problem of my data controls being databound twice. There are at least two causes.

1) The ObjectDataSource control has its EnableViewState property set to false. This results in the DataBind event firing twice.

2) An improperly defined html element on the page may be causing the browser to request the page multiple times. This results in the entire page lifecycle being executed repeatedly and thus resulting in multiple calls to DataBind. Two examples I have noted of improperly defined html tags are

  • An img tag with an empty src attribute
  • Others have mentioned that using the background attribute of a table cell tag (<td>) to set the color for the cell causes the browser to re-request the page. Use the bgcolor attribute instead.

Here are a couple of pages that discuss this problem.

No comments:

Post a Comment