2

I have created a List which generates a custom event based on Example 1 from this page, and I need to update an aspx page whenever there are any new elements in the List.

When I debug the application I can see that the value was updated, but nothing appears on the page.

ASPX

        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
            <ContentTemplate>
                <fieldset>
                <legend>UpdatePanel</legend>
                <asp:Label ID="xpto" runat="server" Text="zzzzzzzzzzzz"></asp:Label>
                </fieldset>
            </ContentTemplate>
        </asp:UpdatePanel>

Code Behind

MessageHandling.DashboardRequests.Changed += new EventHandler(ListChanged);
...
...
...
private void ListChanged(object sender, EventArgs e)
{
    DateTime dt = DateTime.Now;
    xpto.Text = dt.ToString();
}

EDIT:

If I change the UpdateMode to Always and ListChanged method to:

private void ListChanged(object sender, EventArgs e)
{
  DateTime dt = DateTime.Now;
  xpto.Text = dt.ToString();
  UpdatePanel1.Update();
} 

I get the following error:

The Update method can only be called on UpdatePanel with ID 'UpdatePanel1' when UpdateMode is set to Conditional. 

And if I set the UpdateMode to Conditional nothing happens again.

If I create a timer and add this method:

protected void Timer1_Tick(object sender, EventArgs e)
{
  DateTime dt = DateTime.Now;
  xpto.Text = dt.ToString();
}

the xpto is updated in the timer method correctly

5
  • Why are you using UpdateMode="Conditional"? and when are you updating the UpdatePanel? Check UpdatePanel UpdateMode Property Commented Nov 25, 2011 at 16:17
  • @AteşGÜRAL - Your link is wrong I think you meant this msdn.microsoft.com/en-us/library/… Commented Nov 25, 2011 at 16:23
  • Added information in the original post Commented Nov 25, 2011 at 17:13
  • balizeiro I think there is a misunderstanding here, if you set Update mode to Always you don't need to do UpdatePanel1.Update() I mean at least that is how I use it.So set it conditional and do UpdatePanel1.Update() when needed, or set it to always and do not use UpdatePanel1.Update(). Commented Nov 25, 2011 at 21:37
  • I tried both of those manners but nothing happens. The weird thing is if I try the update from a Timer event, everything works OK. Commented Nov 26, 2011 at 18:44

1 Answer 1

1

Change UpdateMode to Always as suggested by Ates.


(old)

The code looks ok, so I will make a WAG -- are you updating xpto.Text ANYWHERE else in the page lifecycle?

Sign up to request clarification or add additional context in comments.

2 Comments

No, the only place where xpto is referenced is in ListChanged(...)
I'd have to see the rest of your code, I will note the example you were looking at is not an ASP.NET example but a windows forms example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.