ASP.NET在UpdatePanel中重复链接按钮时:“需要对象”
我有一个UpdatePanel,它有一个重复链接按钮的中继器。当我单击一个LinkButton时,页面进行部分回发,然后我得到一个javascript错误:objectrequired。我尝试调试javascript,但无法获得调用堆栈。如果我删除UpdatePanel,LinkButtons会进行完整的回发,它们会从页面中消失。我怎样才能让这个UpdatePanel工作ASP.NET在UpdatePanel中重复链接按钮时:“需要对象”,asp.net,javascript,updatepanel,repeater,Asp.net,Javascript,Updatepanel,Repeater,我有一个UpdatePanel,它有一个重复链接按钮的中继器。当我单击一个LinkButton时,页面进行部分回发,然后我得到一个javascript错误:objectrequired。我尝试调试javascript,但无法获得调用堆栈。如果我删除UpdatePanel,LinkButtons会进行完整的回发,它们会从页面中消失。我怎样才能让这个UpdatePanel工作 <ajax:UpdatePanel ID="wrapperUpdatePanel" runat="server" Up
<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>
绑定代码:
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());
}
}
谢谢,
标记这可能不是您的主要问题,但在中继器中包含需要事件的对象时,不应使用该控件的本机事件。相反,您应该使用中继器的事件 如果我猜的话,您的问题是由于中继器没有在回发中维护其数据绑定状态造成的。Linkbutton从视图中消失,因为它在每次回发时都没有绑定到页面,所以当响应被发送回客户端时,它没有绑定到任何内容 听起来UpdatePanel希望从AJAX响应中返回与页面上相同或类似的标记,因此不向转发器返回任何内容会导致问题
尝试将中继器绑定到其OnInit方法中的页/控件。这应该允许在每次回发时加载中继器的ViewState。即使我在第一页进行了绑定,仍然需要获取对象。我想我们需要查看绑定代码