ItemCreated Event of datagrid is firing twice.

  • Thread starter Thread starter archana
  • Start date Start date
A

archana

Hi all,

I am having one datagrid whose datasource i set as array.

On itemcreated event i am having one counter which i have used to find
out how many times item created event is fired.

What i observerd is itemcreated event is fired twice than total items
present in array.

why is it so?

can anyone tell me reason behind this.

thanks in advance.
 
Hi all,

I am having one datagrid whose datasource i set as array.

On itemcreated event i am having one counter which i have used to find
out how many times item created event is fired.

What i observerd is itemcreated event is fired twice than total items
present in array.

why is it so?

can anyone tell me reason behind this.

thanks in advance.

Are you calling DataBind? Are you using an ObjectDataSource?
 
This could happen if you have subscribed to the event twice, e.g. if you have
placed in the HTML markup OnItemCreated and then issued an AddHandler in the
codebehind to wire up the same event. Search your project for the
occurrences of the method name; if you find it wired twice then that is the
cause of it.

Otherwise, it can be due to the databinding happening twice, e.g. if you
databind upon page_load but not use "If Not Page.IsPostBack Then" condition.
Set a break point in the last line of the eventhandler to see from where it
is being called.
 
Back
Top