Jul 17, 2009, 10:09 AM
Update asp.net Repeater with AjaxMethod
Hi,
I'm working on a project using a repeater. But when I update a value using AjaxMethod, it doesnt show right away in codebehind? This has something to do with async postback I think, but is there anyway to get around it, like redrawing the repeater after the operation has finished?
Here's sample code, first the repeater and the links with that calls the AjaxMethods:
I appreciate any help!
I'm working on a project using a repeater. But when I update a value using AjaxMethod, it doesnt show right away in codebehind? This has something to do with async postback I think, but is there anyway to get around it, like redrawing the repeater after the operation has finished?
Here's sample code, first the repeater and the links with that calls the AjaxMethods:
<a href="#" onclick="Coolite.AjaxMethods.btn1_Click()">Click me</a>
<a href="#" onclick="Coolite.AjaxMethods.btn2_Click()">Click me</a>
<asp:repeater id="rpt" runat="server">
<alternatingitemtemplate><div style="float:left;"><%# Eval("FirstName")%>
<div style="float:left;"><%# Eval("LastName")%>
</alternatingitemtemplate>
<itemtemplate><div style="float:left;"><%# Eval("FirstName")%>
<div style="float:left;"><%# Eval("LastName")%>
</itemtemplate>
<separatortemplate><br style="clear:both;" /></separatortemplate>
</asp:repeater>
I bind the repeater in code-behind, and there's also the the buttons, which just switch datasource:protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
rpt.DataSource = TestItems.listTestItem1();
rpt.DataBind();
}
}
[AjaxMethod]
protected void btn1_Click()
{
//rpt.Controls.Clear();
rpt.DataSource = TestItems.listTestItem1();
rpt.DataBind();
}
[AjaxMethod]
protected void btn2_Click()
{
//rpt.Controls.Clear();
rpt.DataSource = TestItems.listTestItem2();
rpt.DataBind();
pnl.Reload();
}
But nothing happens to the repeater when I press the buttons, it doesn't get updated. I've also tried adding and removing an asp:updatepanel to the page, but it makes no difference.I appreciate any help!