0

我在 UpdatePanel 中有一个转发器,当我添加一些文本并提交一个按钮时,更新不会立即出现,但只有在我第二次提交按钮后才会出现。

关于为什么会发生这种情况的任何想法?

谢谢。

 <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!";
            }

        }

编辑 编辑 编辑 编辑 编辑 编辑 编辑 编辑 编辑 编辑 编辑 编辑 编辑 编辑 编辑 编辑 编辑 编辑

我已经更新了 HTML(我已经取出了第二个 UpdatePanel),但仍然得到相同的结果 - 最近的更新直到按钮第二次提交时才会发布。

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


}

}
4

1 回答 1

0

我有点难以遵循您的代码,因为我没有您的 BL 类(Alert、IREspondedProfile 等),所以我猜测一半:
在您的页面加载中,您调用 RespondentProfilePresenter 类的 Init 方法。
此方法调用 ShowDisplay,最终绑定中继器。
请注意,这发生在按下按钮的事件处理程序被触发之前,这是您更新警报列表的代码位置。
在设置中继器的数据源后添加新警报,因此您只能在每隔一个按钮单击时看到更新。您需要重新排序您的代码,使 DataBind 仅在添加新警报后发生。

于 2012-06-01T15:51:14.400 回答