Response.write and ASP.NET controls

Please see the code below:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Response.Write("<table><tr><td>some text</td></tr></table>")
        Response.Flush()
        Threading.Thread.Sleep(3000)
        Response.Write("<table><tr><td>some text</td></tr></table>")
        Response.Flush()
        Threading.Thread.Sleep(3000)
        Response.Write("<table><tr><td>some text</td></tr></table>")
        Response.Flush()
        Threading.Thread.Sleep(3000)
        Response.Write("<table><tr><td>some text</td></tr></table>")
        Response.Flush()
        Threading.Thread.Sleep(3000)
    End Sub

The code works as I would expect i.e. a HTML table is generated and written to the screen, then after three seconds another table is generated and added to the screen etc.

I have a webpage that dynamically adds x number of tables (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.table%28v=vs.110%29.aspx) to a webpage. However, Response.Flush does not seem to work. I have created the simple code below to explain the problem:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Dim Table1 As New Table
        Dim r As New TableRow()
        Dim c As New TableCell()
        c.Text = "Test 1"
        r.Cells.Add(c)
        Table1.Rows.Add(r)
        Response.Flush()
        Threading.Thread.Sleep(3000)

        Dim Table2 As New Table
        Dim r2 As New TableRow()
        Dim c2 As New TableCell()
        c.Text = "Test 2"
        r.Cells.Add(c)
        Table1.Rows.Add(r)
    End Sub

Is it possible to flush table1 to the client, then wait a few seconds then flush table2 or do you have to write a string to response.write?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

To use Response.Flush in that way you need to output all the HTML code yourself using Response.Write.

You can’t use web controls as they are not rendered until the page is complete. The web controls only exist as objects until the Page_Render stage where the entire page is rendered as HTML code and then sent to the browser.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x