简体   繁体   中英

Response.Write() in Umbraco user control clears all page content

I'm using the following code to add a table to a user control in Umbraco.

Try
    Dim DS As DataSet = GetData()
    If DS.Tables(0).Rows.Count > 0 Then
        Response.Write("<form><table>")
        For Each row In DS.Tables(0).Rows
            Response.Write("<tr>")
            Response.Write("<td> <a onclick=alert('" & row("ID") & "')>" & row("Date") & "</a></td>")
            Response.Write("<td>" & " - " & "</td>")
            Response.Write("<td>" & row("Amount") & "</td>")
            Response.Write("</tr>")
        Next
        Response.Write("</table></form>")
        Response.End()
    End If
Catch ex As Exception
    Response.End()
End Try

But what happens after the loop completes (without errors - I've stepped through the whole thing), the only content left on the page is the table.

I'm sure there's something really silly I left out. Any help?

Thanks!

Response.Write() isn't to blame in this instance, it's your Response.End() calls. It's not clearing the remaining page content, but actually preventing it from being run.

HttpResponse.End Method
Sends all currently buffered output to the client, stops execution of the page, and raises the EndRequest event.

http://msdn.microsoft.com/en-us/library/system.web.httpresponse.end.aspx

Remove them (or at least the one in the try block, if the one in the catch statement is intended) and that should fix it for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM