views:

136

answers:

2
<asp:Repeater ID="repFilter" runat="server">
                        <HeaderTemplate>
                            <div id="posting" align="center">
                        </HeaderTemplate>

                        <ItemTemplate>
                            <div class="friends_area" id="record-">
                                <%# ((Alert)Container.DataItem).Message %>
                                <asp:Literal Visible="false" ID="litAlertId" Text='<%# ((Alert)Container.DataItem).AlertId %>' runat="server"></asp:Literal>
                                <Company:Comments ID="Comments1" SystemObjectRecordId='<%# ((Alert)Container.DataItem).AlertId %>' runat="server" SystemObjectId="7"></Company:Comments>
                            </div>
                        </ItemTemplate>

                        <FooterTemplate>
                            </div>
                        </FooterTemplate>
                    </asp:Repeater>

I am having a problem setting the SystemObjectRecordID attribute of my custom control inside a repeater. Currently, the value winds up as zero in the database. Things I have checked / worth pointing out:

1) AlertId is an Primary Key Identity column in the database and the table has numerous rows so AlertId should be returning multiple values.

2) The datatype of the DB column (bigint) and the datatype of AlertId (long) and the datatype of the getter/setter SystemObjectRecordID variable (long) match.

3) If I set '<%# ((Alert)Container.DataItem).AlertId %>' to the Text attribute of a literal I get the expected results. So, it has something to do with my custom control and specifically how data is bound to the SystemObjectRecordID attribute.

4) If I change SystemObjectRecordID from long to string and then do ((Alert)Container.DataItem).AlertId.ToString() the value I get for SystemObjectRecordId in debug is null (but it still works when assigned to the text attribute of a literal).

5) The location of the User Control is default.aspx and the control is comments.ascx. The code files do not share a namespace.

6) I have tried manipulating the OnItemDataBound property of my repeater but since I have proven with the literal that data is getting bound using a declarative value I am not sure what else I could be doing inside the method logic of OnItemDataBound.

Once the end-user makes a comment in the UI, the SystemObjectRecordId value (which should have already been assigned when the page loaded - and we know it does in the case of the literal) should get passed to the codebehind of the custom usercontrol:

namespace Company.ProjectWeb.UserControls
{
    public partial class Comments : UserControl, IComments
    {
        private readonly IUserSession _userSession;
        private CommentsPresenter _presenter;
        public int SystemObjectId { get; set; }
        public long SystemObjectRecordId { get; set; }

No matter what I do, I always get zero for SystemObjectRecordId when passed via the custom user control I have on my default.aspx page. I am out of ideas - could use some suggestions at this point. Thanks.

A: 

OK, I have figured out a work-around for this by adding SystemObjectRecordId to the ViewState:

public long SystemObjectRecordId
        {
            get
            {
                if (ViewState["SystemObjectRecordId"] != null)
                    return long.Parse(ViewState["SystemObjectRecordId"].ToString());
                else
                    return 0;
            }
            set
            {
                ViewState["SystemObjectRecordId"] = value;
            }
        }

Its not idea, but it works. I still don't get why I can't set the declarative value as previously specified but this will have to do for now.

Code Sherpa
A: 

You should be able to fix this by adding the Bindable attribute to your SystemObjectRecordId poperty.

jrummell
Hi, thanks. I already tried that and it didn't work.
Code Sherpa