Asp.Net: Beware of the comment devil: How to save hours of time

April 29, 2004

You are experiencing the following symptoms when trying to use an inside a Repeater, DataList or DataGrid.

Javascript Error: Error On Page
Line: 1
Char: 1
Error: Object Expected
Code: 0

When you place a LinkButton inside one of the databound repeating controls, generates a javascript function to deal with the OnClick event of each LinkButton it ends up placing on the page. (Note the number of LinkButtons will depend on how many items of data you are displaying)

function __doPostBack(eventTarget, eventArgument) { … }

Please, oh please make sure that you have closed off all comments in your html <head> section. By failing to close off your comments in your head section you are effectively commenting out the javascript code that creates to handle your events on the Repeater/DataList/DataGrid Control. By commenting this function out it is now inaccessable during the processing of the OnClick event of the LinkButton, hence your page is broken.

Props to Mun for helping me find this one.

Note: You can visit my Marks Asp.Net Journals Post for an index of all the Asp.Net tips and tricks I have painfully learned during my Asp.Net Adventures.