Checkbox Event Firing

  • Thread starter Thread starter Jack Turnbull
  • Start date Start date
J

Jack Turnbull

Hi,
I have a Checkbox in a Repeater set to AutoPostBack = true. I have pointed
OnCheckedChanged to a Sub but it doesn't fire. If I move the checkbox out of
the Repeater it fires! Any ideas?
Thanks
 
Nested controls usually don't raise their own events. I can think of a
couple of ways to handle this: neither is elegant, only one I have done
myself.

The one I have done is to put a hidden button (visible=false) on the page
and use Javascript on the checkbox to trigger a postback as if the hidden
control had been clicked. If you need to access the specific line that
had the checkbox clicked, I would put a button inside the ItemTemplate so
that you could respond to the repeater.ItemCommand event and get the line
item. Otherwise, you can put the button outside the repeater and trigger
it.

The other way I could think of is to loop though the repeater during
postback and find out if the checkbox has changed. Not very efficient at
all. You may want that for some very odd reason.

Heres a quick code snip:

<FooterTemplate>
<input type="checkbox" ID="cmdTriggerDelete" value="Delete"
OnClick="__doPostBack('cmdDelete','click');" />
</FooterTemplate>
</asp:Repeater>

<asp:Button Runat=server ID="cmdDelete" Visible=false />
 
Thanks Guys,
I'll take the solution to wire a hidden button - I already have a button in
each row, I'll just hide it. The idea was to get rid of it to prevent the
user getting miffed at no update on clicking the button on a different row
to the checkbox change.
Thanks & Cheers
 
Back
Top