0

I have a repeater in an UpdatePanel and when I add some text and submit a button, the update does not appear immediately, but only after I submit the button a second time.

Any thoughts as to why this is happening?

Thanks.

 <asp:UpdatePanel ID="updateStatus" UpdateMode="Conditional" runat="server">
        <ContentTemplate>
            <table border="">
                <tbody>
                <asp:TextBox Width="520" Height="35" style="font-size:13px;padding-left:0px;padding-right:0px;" id="txtStatusUpdate" runat="server"></asp:TextBox>
                <asp:UpdatePanel ID="updButton" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <asp:Button style="font-size:25px;padding-left:0px;padding-right:0px;" ID="btnAddStatus" runat="server" Text="Add" OnClick="btnAddStatus_Click" />
                    </ContentTemplate>
                </asp:UpdatePanel>
                <asp:Repeater ID="repFilter" runat="server">
                    <ItemTemplate>
                        <tr>
                            <td class="date"><%# String.Format("{0:MM/dd/yyy}", ((Alert)Container.DataItem).CreateDate) %></td>
                            <td><%# ((Alert)Container.DataItem).Message  %></td>
                        </tr>
                    </ItemTemplate>
                </asp:Repeater>
                </tbody>
            </table>
        </ContentTemplate>      
        </asp:UpdatePanel>



protected void Page_Load(object sender, EventArgs e)
{

            _presenter = new RespondentProfilePresenter();
            _presenter.Init(this);
}


 protected void btnAddStatus_Click(object sender, EventArgs e)
        {
            StatusUpdate su = new StatusUpdate();
            su.CreateDate = DateTime.Now;
            su.AccountID =  _userSession.CurrentUser.AccountID;
            su.Status = txtStatusUpdate.Text;
            _statusRepository.SaveStatusUpdate(su);
            _alertService.AddStatusUpdateAlert(su);

            updateStatus.Update();

            //_redirector.GoToHomePage();
        }

 public void ShowAlerts(List<Alert> alerts)
        {

            repFilter.DataSource = alerts;
            repFilter.DataBind();

            if (repFilter.Items.Count == 0)
            {
                //lblMessage.Text = "You don't have any alerts yet!";
            }

        }

EDIT EDITEDIT EDITEDIT EDITEDIT EDITEDIT EDITEDIT EDITEDIT EDITEDIT EDITEDIT EDITEDIT EDIT

I have updated the HTML (I have taken out the second UpdatePanel) but am still getting the same results - the most recent update does not post until the second time the button submits.

   <asp:UpdatePanel ID="updateStatus" UpdateMode="Conditional" runat="server">
         <ContentTemplate>
            <asp:TextBox Width="520" Height="35" style="font-size:13px;padding-left:0px;padding-right:0px;" id="txtStatusUpdate" runat="server"></asp:TextBox>
            <asp:Button style="font-size:25px;padding-left:0px;padding-right:0px;" ID="btnAddStatus" runat="server" Text="Add" OnClick="btnAddStatus_Click" />
            <table border="">
                <tbody>
                <asp:Repeater ID="repFilter" runat="server">
                    <ItemTemplate>
                        <tr>
                            <td class="date"><%# String.Format("{0:MM/dd/yyy}", ((Alert)Container.DataItem).CreateDate) %></td>
                            <td><%# ((Alert)Container.DataItem).Message  %></td>
                        </tr>
                    </ItemTemplate>
                </asp:Repeater>
                </tbody>
            </table>
        </ContentTemplate>      
        </asp:UpdatePanel>

  public class RespondentProfilePresenter
    {


     //CODE HERE....
public void Init(IRespondentProfile View)
        {
            _view = View;

            _view.SetAvatar(_accountBeingViewed.AccountID);
            _view.DisplayInfo(_accountBeingViewed);

            if (_userSession.CurrentUser != null)
                ShowDisplay();

            TogglePrivacy();
        }


private void ShowDisplay()
{

    List<Alert> _objAlerts = _alertService.GetAlertsByAccountID(_userSession.CurrentUser.AccountID);

    _view.ShowAlerts(_objAlerts);


}

}
Peter
  • 5,251
  • 16
  • 63
  • 98
  • why do you use 2 update panels, one within the other? what happens at first click? did you debug and reached the event handler? – YavgenyP May 31 '12 at 20:36
  • It was a hold-over from another post that had suggested it. I took it out with the same result. If I put a break-point on "StatusUpdate us = StatusUpdate();" it gets hit when i submit the button and I do get a partial post-back of the page but the most recent text from the txtStatusUpdate.Text field does not show up until I do another submit of the button. – Peter May 31 '12 at 21:01
  • Anybody else? Anything I can add to make this question clearer? – Peter Jun 01 '12 at 14:05
  • the textbox updates fine on my side. I dont fully understand your question: what doesnt update? the content of the repeater or the textbox or both? if its the repeater - are you sure you provde different data to start with? In the code you provided (c# event handlers) I dont see any attepmpts to update neither the textbox nore the repeater.. – YavgenyP Jun 01 '12 at 14:17
  • Hi YavgenyP, I have added more code. The design is MVP and the C# code before the edit is in the Profile.aspx.cs file. The C# code after the edit is in the Presenter. The presenter passes all the alerts to ShowAlerts in the Profile.aspx.cs file. It is here that the repeater is databound. If I put "updateStatus.Update();" at the end of ShowAlerts, I still have the same problem - the most recent alert is not shown until the next time the button is submitted. – Peter Jun 01 '12 at 15:41

1 Answers1

0

Its a bit hard for me to follow your code, as I dont have your BL classes (Alert, IREspondedProfile etc), so Im going to half guess:
Within your page load, you call the Init method of the RespondentProfilePresenter class.
This method calls ShowDisplay, which eventually binds the repeater.
Notice that this happens BEFORE the event handler of the pressed button is fired, which is the place in code where You update your alerts list.
Your new alert is added AFTER the data source for the repeater is set, and therefor You only see the update on every other button click. You need to reorder Your code in such way that the DataBind will occur only AFTER the addition of the new alert.

YavgenyP
  • 2,113
  • 14
  • 11