<ASP:Repeater id="PickListRepeater" runat="server" datasource="<%#
PickListQuery %>">
<ItemTemplate>
<input id="RES_SEQ" type="hidden" value='<%#
DataBinder.Eval(Container.DataItem, "RES_SEQ") %>' />
<lw:TLWRemoveCheckBox id="RemoveCheckBox" runat="server"
Seq='5'
oncheckedchanged="RemoveCheckBoxCheckChanged">
</ItemTemplate>
</ASP:Repeater>
When my page gets posted back, if I've clicked on one of my
RemoveCheckBoxes, I can reference the Seq property and see the 5 in there.
Plus, if I look at the page source at the browser, I can see that my RES_SEQ
hidden input has evaluated properly for each line (RES_SEQ is a database
key).
Now, what doesn't work is this:
<ASP:Repeater id="PickListRepeater" runat="server" datasource="<%#
PickListQuery %>">
<ItemTemplate>
<input id="RES_SEQ" type="hidden" value='<%#
DataBinder.Eval(Container.DataItem, "RES_SEQ") %>' />
<lw:TLWRemoveCheckBox id="RemoveCheckBox" runat="server"
Seq='<%# DataBinder.Eval(Container.DataItem, "RES_SEQ") %>'
oncheckedchanged="RemoveCheckBoxCheckChanged">
</ItemTemplate>
</ASP:Repeater>
The only thing different is that I've replaced the 5 with <%#
DataBinder.Eval(Container.DataItem, "RES_SEQ") %> so that Seq will have a
generated value for each instance of RemoveCheckBox. I don't get an error,
I just find that Seq is an empty string on post back. What gives? Even
using the Eval with asp:TextBox works as expected:
<ASP:Repeater id="PickListRepeater" runat="server" datasource="<%#
PickListQuery %>">
<ItemTemplate>
<input id="RES_SEQ" type="hidden" value='<%#
DataBinder.Eval(Container.DataItem, "RES_SEQ") %>' />
<asp:TextBox runat="server" id="fubar" text='<%#
DataBinder.Eval(Container.DataItem, "RES_SEQ") %>'></asp:textbox>
<lw:TLWRemoveCheckBox id="RemoveCheckBox" runat="server"
Seq='<%# DataBinder.Eval(Container.DataItem, "RES_SEQ") %>'
oncheckedchanged="RemoveCheckBoxCheckChanged">
</lw:TLWRemoveCheckBox>
</ItemTemplate>
</ASP:Repeater>
Any thoughts much appreciated.
Thanks,
Kevin Donn
<lw:TLWRemoveCheckBox id="RemoveCheckBox" runat="server"
Seq='5'
oncheckedchanged="RemoveCheckBoxCheckChanged">
and this:
<lw:TLWRemoveCheckBox id="RemoveCheckBox" runat="server"
Seq='<%# DataBinder.Eval(Container.DataItem, "RES_SEQ") %>'
oncheckedchanged="RemoveCheckBoxCheckChanged">
is that the first being a literal wouldn't be dependent upon ViewState. The
5 would be there after page load whether it was in ViewState or not. Also I
added this handler:
procedure TWebForm1.PickListRepeater_ItemDataBound(sender: System.Object; e:
System.Web.UI.WebControls.RepeaterItemEventArgs);
begin
if e.Item.ItemType=ListItemType.Item then
Response.Write(TLWRemoveCheckBox(e.Item.FindControl('RemoveCheckBox')).Seq+'<BR>'#10)
end;
And was able to confirm that each instance of RemoveCheckBox is definitely
getting a value. They just don't appear to be making the round trip back to
the server. I tried "EnableViewState:=true" in my constructor but that
didn't work. Is there something special I need to do to get this property
into the ViewState?
Kevin Donn
TLWRemoveCheckBox = class(System.Web.UI.WebControls.CheckBox)
private
FSeq: string;
published
[Bindable(true), Category('Appearance'), DefaultValue('')]
property Seq: string read FSeq write FSeq;
end;
What I needed was:
property Seq: string read GetSeq write SetSeq;
function TLWRemoveCheckBox.GetSeq: string;
begin
result:=string(ViewState['Seq'])
end;
procedure TLWRemoveCheckBox.SetString(const value: string);
begin
ViewState['Seq']:=value
end;
I was imagining that properties, particularly published properties, would be
persisted in the ViewState automatically, but not so.
Kevin Donn
Thanks,
Kevin Donn