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);
}
}
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.