当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - ASP.NET: "Object Required" when repeating LinkButtons in an UpdatePanel

问题描述:

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

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: