0

UpdatePanelにリピーターがあり、テキストを追加してボタンを送信すると、更新はすぐには表示されませんが、ボタンを2回送信した後にのみ表示されます。

なぜこれが起こっているのかについて何か考えはありますか?

ありがとう。

 <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

HTMLを更新しました(2番目のUpdatePanelを取り出しました)が、それでも同じ結果が得られます。最新の更新は、ボタンが2回送信されるまで投稿されません。

   <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を呼び出し、最終的にリピーターをバインドします。
これは、押されたボタンのイベントハンドラーが起動される前に発生することに注意してください。これは、アラートリストを更新するコード内の場所です。
リピーターのデータソースが設定された後に新しいアラートが追加されるため、ボタンを1回クリックするたびにのみ更新が表示されます。新しいアラートを追加した後にのみDataBindが発生するように、コードを並べ替える必要があります。

于 2012-06-01T15:51:14.400 に答える