Update asp.net Repeater with AjaxMethod

  1. #1

    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:

    <a href="#" &#111;nclick="Coolite.AjaxMethods.btn1_Click()">Click me</a>
    <a href="#" &#111;nclick="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!
  2. #2

    RE: Update asp.net Repeater with AjaxMethod

    the ajaxmethod must be public
  3. #3

    RE: Update asp.net Repeater with AjaxMethod

    I still have the same problem even if I set the AjaxMethod to public.

    Any other suggestions?
  4. #4

    RE: Update asp.net Repeater with AjaxMethod

    Hi,

    Try wrapping your repeater in an update panel and then putting an asp:Button inside the panel also. I set this to display:none (so it doesnt show).

    I guess you want to modify your data so I use an AjaxMethod call with a callback. The ajax method modifies my data and on the call back I use jquery to fire the asp:Button click. The asp:Button you wire up to rebind your repeater and as its in the update panel it will refresh.

    Hope this works for you.

Similar Threads

  1. Replies: 1
    Last Post: Mar 27, 2012, 2:36 AM
  2. Repeater inside GridPanel
    By bruno in forum 1.x Help
    Replies: 1
    Last Post: Sep 15, 2011, 4:40 PM
  3. [1.0] Repeater and TabPanel
    By SouthDeveloper in forum 1.x Help
    Replies: 3
    Last Post: May 18, 2010, 4:28 PM
  4. [CLOSED] Update label Icon over AjaxMethod
    By reinout.mechant@imprss.be in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: Jun 07, 2009, 2:48 AM
  5. How do I update an image url via an AjaxMethod?
    By dbassett74 in forum 1.x Help
    Replies: 1
    Last Post: Apr 28, 2009, 11:12 AM

Posting Permissions