How to do client callback for each item in a foreach statement using c#?

Posted by Mike108 on Stack Overflow See other posts from Stack Overflow or by Mike108
Published on 2010-05-09T08:34:20Z Indexed on 2010/05/09 8:38 UTC
Read the original article Hit count: 249

Filed under:
|

I want to show each item Id that is doing now dynamically in a foreach statement. How to do some kind of client callback to show the item Id in a foreach statement?

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

.

protected void Button1_Click(object sender, EventArgs e)
    {
        List<int> list = new List<int>()
        {
            1,2,3,4,5
        };

        foreach (var item in list)
        {
            Label1.Text = string.Format("I'm doing item {0} now.", item.ToString());
Page.RegisterStartupScript("", string.Format("<script>alert('doing item {0} now')</script>", item.ToString()));
            Thread.Sleep(1 * 1000);
        }
    }

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#