"Jos" <> wrote...
> I guess there's an easier way, but I once worked around this
> by "hiding" the RecordKey inside the checkbox's ID, like this:
>
> <asp:checkbox ID='cb_<%# DataBinder.Eval(Container.DataItem,"RecordKey") %>'
> ...
>
> I use the prefix "cb_" because RecordKeys are usually numbers, which are not
> allowed for ID's.
>
> On postback, you can then extract the RecordKey from the checkbox's ID.
I decided for lack of better approaches for storage, to create a
custom web control with the checkbox class as its base. So basically,
my CustomCheckBox control has all properties of the original control,
plus a RecordKey. I figured that would do the trick, as I could spin
through the values for each of these controls either on the
CheckChanged event, or in worst case scenario, call a function to do
that from the PostBack = True section of my Page_Load. I've traced
through my code in all cases, and noticed the order of the events as
they happen upon my save button click event (Page_Load - PostBack,
CheckChanged event for each checkbox changed in my repeater,
btnSave_Click). Even on the postback, the RecordKey value for each
checkbox is returning as an all-zero guid (as I am using guids for
record keys in this application). I've tried everything from using
the FindControl method to cycling through each control in the
repeater, using nested For loops to get to every control's properties,
in each of these events/functions with no luck. Is there some way I
can cause the control to keep the RecordKey property? I know the
value is being assigned initially, as I also tested output of a label
next to each checkbox, and the record key is showing correctly for
each. I guess the big question is whether the value is being lost due
to the checkbox being contained within the repeater, or if it's just
not maintaining viewstate despite setting properties to
EnableViewState = True for the checkbox and/or the repeater it's
contained within. Thanks again for your help!
Brian
|