473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

UserControl.Page_PreRender: the Response.Write text appears before the page contents.

Hi,

I have a user control that shows the contents of potentially big html files.

To save the server memory, I try to avoid reading the whole large-file's
text into a label or literal control. Therefore, I tried to use this code in
the user control's code behind:

protected void Page_Load(object sender, EventArgs e)// Also tried
Page_PreRender, same problem!

{

Response.WriteFile(HTMLFileName);

}

The code doesn't work because it dumps the file before the actual page tags.
How can I directly dump a text file at the position of the actual user
control?

Thank you,

Max
Aug 3 '06 #1
1 2052
Hello Max,

As for dumping some text data directly in a specified postion in an ascx
usercontrol, you can consider use the inline rendering expression <%= %>
and call a helper function to output the text in it. For example:

=========ascx template=============
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TextUC.ascx.cs"
Inherits="UserControl_TextUC" %>
<table style="width:100%">
<tr>
<td >
<%= GetLargeText() %>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
==============================

======code behind==============
public partial class UserControl_TextUC : System.Web.UI.UserControl
{

protected string GetLargeText()
{
StreamReader sr = new StreamReader(@"D:\temp\my.log");

string text = Server.HtmlEncode(sr.ReadToEnd());

sr.Close();

return text;
}
}

}
============================
Because such inline render experssion <%= %is called at the whole page's
output rendering, the data returned in the expression will be inserted at
the specfiied position in the page's output content.

As for the response.Write method, it will always write the data into the
Page's response stream directly, at generally before page's Render event,
the page's whole output content has not been flushed yet, so any data write
through "Response.Write" will occur at the top of the page output.

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Aug 3 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Will Gillen | last post by:
I know this has probably been asked before, but I can't seem to find a solid answer in any of the archives. First, before my question, please forgive my limited knowledge of the event lifecycle...
12
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
5
by: seal | last post by:
OK, I am trying to fire an event from a usercontrol that tells the page when a checkbox was clicked. Here is the control and when I try and wire up the page to catch the event, my event is not...
1
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.