I have some problems regarding events from a checkbox in a templatecolumn in a datagrid.
This is what is looks like:
I have a datagrid with a few columns and a template column containing a checkbox.
To this checkbox I have added an event handler for the CheckedChanged event.
EnableViewState for the datagrid is set to false (I want to keep it to the minimum).
The problem is that the CheckedChanged event is only fired after a first postback.
e.g. If you press the checkbox, a postback is initiated but no CheckedChanged event is fired... but after this postback it works like a charm.
To maintain viewstate I do the following:
In Page_Init(...) i create all the datagrid columns and rebinds the grid to have it populated with
with data.
I have noticed one strange thing though:
The first time I press the checkbox the value of __EVENTTARGET points to the checkbox that was checked... so far so good - but why is the event not fired?
After this first try it works all the time, but the value if __EVENTTARGET does NOT point to the checkbox. if I pressed on "DataGrid1$ctl02$GridCheckBox" (the grid contains 5 items), the value of __EVENTTARGET is "DataGrid1$ctl09$GridCheckBox"
It seems like the grid was populated twice (but it´s not) and the count just continued.
Does anyone have a clue what´s causing this behaviour?
Any help is appreciated.
mystiqu
Member
80 Points
16 Posts
Strange event behaviour __EVENTTARGET pointing to non-existing control
Feb 17, 2006 11:20 AM|LINK
Hi
I have some problems regarding events from a checkbox in a templatecolumn in a datagrid.
This is what is looks like:
I have a datagrid with a few columns and a template column containing a checkbox.
To this checkbox I have added an event handler for the CheckedChanged event.
EnableViewState for the datagrid is set to false (I want to keep it to the minimum).
The problem is that the CheckedChanged event is only fired after a first postback.
e.g. If you press the checkbox, a postback is initiated but no CheckedChanged event is fired... but after this postback it works like a charm.
To maintain viewstate I do the following:
In Page_Init(...) i create all the datagrid columns and rebinds the grid to have it populated with
with data.
I have noticed one strange thing though:
The first time I press the checkbox the value of __EVENTTARGET points to the checkbox that was checked... so far so good - but why is the event not fired?
After this first try it works all the time, but the value if __EVENTTARGET does NOT point to the checkbox. if I pressed on "DataGrid1$ctl02$GridCheckBox" (the grid contains 5 items), the value of __EVENTTARGET is "DataGrid1$ctl09$GridCheckBox"
It seems like the grid was populated twice (but it´s not) and the count just continued.
Does anyone have a clue what´s causing this behaviour?
Any help is appreciated.
Regards
Mikael