LinkButton Inside a Repeater in an UpdatePanel Causes Full Postback
If you place LinkButton inside a repeater which is inside an UpdatePanel, you will get a full postback if you click on the LinkButton.
Take this code for example:
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="MobInvestor3.Test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div style="width:35px;height:800px;background:yellow;"> </div>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<p>Update Panel 2</p>
<p><asp:LinkButton ID="LinkButton2" Text="LinkButton OUTSIDE REPEATER 1" runat="server" /></p>
<p><asp:LinkButton ID="LinkButton1" Text="LinkButton OUTSIDE REPEATER 2" runat="server" /></p>
<p><asp:Button ID="Button2" runat="server" Text="INSIDE UpdatePanel 2..." /></p>
<p><asp:LinkButton ID="LinkButton3" Text="LinkButton Without ID" runat="server" /></p>
<asp:Repeater ID="rpt" runat="server">
<HeaderTemplate><hr /></HeaderTemplate>
<ItemTemplate>
<p><asp:LinkButton ID="lb" Text="LinkButton INSIDE REPEATER" runat="server" /></p>
</ItemTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
On code behind use this for testing:
Code:
protected void Page_Load(object sender, EventArgs e)
{
ArrayList al = new ArrayList();
al.Add("1");
al.Add("1");
rpt.DataSource = al;
rpt.DataBind();
}
On the rendered page if you click on the link button lb (Linkbutton INSIDE REPEATER) you would get a full postback instead of partial rendering.
Reason?
I dont know the cause really.
Solution?
On code behind register the linkbutton inside the repeater for Asynchronous postback.
Like this
Code:
protected void Page_Load(object sender, EventArgs e)
{
ArrayList al = new ArrayList();
al.Add("1");
al.Add("1");
rpt.DataSource = al;
rpt.DataBind();
foreach (RepeaterItem ri in rpt.Items)
{
if (ri.ItemType == ListItemType.Item || ri.ItemType == ListItemType.AlternatingItem)
{
LinkButton lb = (LinkButton)ri.FindControl("lb");
ScriptManager1.RegisterAsyncPostBackControl(lb);
}
}
}
I heard some people get full postback if they put the ID of the linkbutton. You should check to make sure put an ID.