views:

585

answers:

1

I have an UpdatePanel which has a Repeater repeating LinkButtons. When I click a LinkButton, the page does a partial postback, then I get a javascript error: "Object required". I tried debugging the javascript, but couldn't get a call stack. If I remove the UpdatePanel, the LinkButtons do a full postback, and they disappear from the page. How can I get this UpdatePanel to work?

<ajax:UpdatePanel ID="wrapperUpdatePanel" runat="server" UpdateMode="Always">
    <ContentTemplate>
        <asp:Repeater ID="endpointRepeater" runat="server" OnItemDataBound="EndpointDataBound">
            <HeaderTemplate>
                <div class="sideTabs">
                    <ul>
            </HeaderTemplate>
            <ItemTemplate>
                <li>
                    <asp:LinkButton ID="endpointLink" runat="server" OnClick="EndpointSelected" />
                </li>
            </ItemTemplate>
            <FooterTemplate>
                </ul>
                </div>
            </FooterTemplate>
        </asp:Repeater>
    </ContentTemplate>
</ajax:UpdatePanel>

binding code:

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        this.SelectedEndpoint = Factory.Get<IEndpoint>(Enums.EndPoints.Marketing);
    }
    IEndpointCollection col = EndpointCollection.GetActivelySubscribingEndpointsForPart(this.Item);

    if (this.Item.IsGdsnItem)
        col.Add(Factory.Get<IEndpoint>(Enums.EndPoints.Gdsn));

    if (col.Count > 0)
        col.Insert(0, Factory.Get<IEndpoint>(Enums.EndPoints.Marketing));

    this.endpointRepeater.DataSource = col;
    this.endpointRepeater.DataBind();

    if (this.endpointRepeater.Items.Count > 0)
    {
        LinkButton lb = this.endpointRepeater.Items[0].FindControl("endpointLink") as LinkButton;
        this.EndpointSelected(lb, new EventArgs());
    }
}

thanks, mark

A: 

This may not be your main issue, but when including an object inside a Repeater that needs an event, you shouldn't be using that control's native events. Instead you should use the Repeater's OnCommand event.

If I were to guess, your problem is caused by the repeater not maintaining its DataBound state across PostBacks. The Linkbutton disappears from view because it is not bound to the page on every PostBack, so when the response is sent back to the client, it has nothing bound to it.

It sounds like the UpdatePanel is expecting the same (or similar) markup to be returned from the AJAX response as what is on the page already, so returning nothing for the repeater causes problems.

Try binding your repeater to the page/control in its OnInit() method. This should allow the ViewState for the repeater to be loaded on every PostBack.

Dan Herbert
still getting "object required" even if I do binding in Page_Init
MStodd