473,320 Members | 1,902 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,320 software developers and data experts.

Response.write

oz
Hi,
just wondering about the following. if you put this statement in the page
load event of the code behind file.

Response.Write("Hello Asp.net");

Then run the page, then use the view source in the browser. the "Hello
Asp.net" is printed before the HTML and Body of the page. Please let me know
why this is.
Thanks...
Nov 19 '05 #1
7 4560
Primarily because this isn't ASP and ASP.Net behaves very differently and
uses an event-driven model. A Response.Write dumps out the string during
certain events that occur during the page's execution. Basically, it's
sending all the HTML code last and the response.write will be sent earlier
because of the event it occurs in, usually the Page_Load event.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"oz" <oz@discussions.microsoft.com> wrote in message
news:DD**********************************@microsof t.com...
Hi,
just wondering about the following. if you put this statement in the page
load event of the code behind file.

Response.Write("Hello Asp.net");

Then run the page, then use the view source in the browser. the "Hello
Asp.net" is printed before the HTML and Body of the page. Please let me
know
why this is.
Thanks...

Nov 19 '05 #2
oz wrote:
if you put this statement in the page
load event of the code behind file.

Response.Write("Hello Asp.net");

Then run the page, then use the view source in the browser. the "Hello
Asp.net" is printed before the HTML and Body of the page. Please let me know
why this is.

This is because you write it to the response stream before any other
output has been written to it. ASP.NET emits the HTML code for the page
when the page's Render method has been called. This is the last event in
the life cycle before the page is disposed.

To write "Hello ASP.NET" within the body I suggest you either place a
Label control in the body and set the Text property of this control or
use the Response.Write method within the BODY element of the HTML code.

<BODY>
<% Response.Write("Hello ASP.NET"); %>
</BODY>

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 19 '05 #3
oz
I put the code in the prerender event still the same issue

"Mark Fitzpatrick" wrote:
Primarily because this isn't ASP and ASP.Net behaves very differently and
uses an event-driven model. A Response.Write dumps out the string during
certain events that occur during the page's execution. Basically, it's
sending all the HTML code last and the response.write will be sent earlier
because of the event it occurs in, usually the Page_Load event.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"oz" <oz@discussions.microsoft.com> wrote in message
news:DD**********************************@microsof t.com...
Hi,
just wondering about the following. if you put this statement in the page
load event of the code behind file.

Response.Write("Hello Asp.net");

Then run the page, then use the view source in the browser. the "Hello
Asp.net" is printed before the HTML and Body of the page. Please let me
know
why this is.
Thanks...


Nov 19 '05 #4
oz
there is no render, I put the code in the prerender event, with the same
problem, just out of curious....this is taking me into the birth of the page
:)......

"Anders Norås [MCAD]" wrote:
oz wrote:
if you put this statement in the page
load event of the code behind file.

Response.Write("Hello Asp.net");

Then run the page, then use the view source in the browser. the "Hello
Asp.net" is printed before the HTML and Body of the page. Please let me know
why this is.

This is because you write it to the response stream before any other
output has been written to it. ASP.NET emits the HTML code for the page
when the page's Render method has been called. This is the last event in
the life cycle before the page is disposed.

To write "Hello ASP.NET" within the body I suggest you either place a
Label control in the body and set the Text property of this control or
use the Response.Write method within the BODY element of the HTML code.

<BODY>
<% Response.Write("Hello ASP.NET"); %>
</BODY>

Anders Norås
http://dotnetjunkies.com/weblog/anoras/

Nov 19 '05 #5
oz wrote:
there is no render, I put the code in the prerender event, with the same
problem, just out of curious....this is taking me into the birth of the page
:)......

The System.Web.UI.Page class has a render method. Your page inherits
this method. An ASP.NET page has this lifecycle:
1. Instantiate
2. Initialize
3. TrackViewState
4. LoadViewState (postback)
5. Load postback data (postback, IPostBackDatahandler.LoadPostdata)
6. Load
7. Load postback data for dynamical controls added on Page_Load
8. Raise Changed Events (postback,
IPostBackDatahandler.RaisePostDataChanged)
9. Raise postback event (postback, IPostBackEventHandler.RaisePostBackEvent)
10.PreRender
11. SaveViewState
12. Render
13. Unload
14. Dispose

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 19 '05 #6
oz
Thanks for the detailed lifecycleof the page...Isn't everything in a web page
suppose to be inside the html and body tags...with the exception of page
directives and header...should asp.net raise an error in this case?

"Anders Norås [MCAD]" wrote:
oz wrote:
there is no render, I put the code in the prerender event, with the same
problem, just out of curious....this is taking me into the birth of the page
:)......

The System.Web.UI.Page class has a render method. Your page inherits
this method. An ASP.NET page has this lifecycle:
1. Instantiate
2. Initialize
3. TrackViewState
4. LoadViewState (postback)
5. Load postback data (postback, IPostBackDatahandler.LoadPostdata)
6. Load
7. Load postback data for dynamical controls added on Page_Load
8. Raise Changed Events (postback,
IPostBackDatahandler.RaisePostDataChanged)
9. Raise postback event (postback, IPostBackEventHandler.RaisePostBackEvent)
10.PreRender
11. SaveViewState
12. Render
13. Unload
14. Dispose

Anders Norås
http://dotnetjunkies.com/weblog/anoras/

Nov 19 '05 #7
"oz" <oz@discussions.microsoft.com> wrote
Thanks for the detailed lifecycleof the page...Isn't everything in a web page suppose to be inside the html and body tags...with the exception of page
directives and header...should asp.net raise an error in this case?


Browsers don't tend to be fussy with errors for this (although the results
of styles and scripts might be less predictable - if you are fussy about
this, you could argue that ASP doesn't produce conforming pages anyway, as
it inludes the invalid ms-positioning property in tags.).

However this is really beyond the point, so I will get back to that. You
really have a few options. If you must use respone.write mixed in with other
code, stick to using it inline, or call procedures that use it from inline

eg
webpage

<% response.write("something") %>
<% aProcedure() %>

code behind and/or server script blocks
Sub aProcedure()
response.write("something else")
End Sub aProcedure

Alternatively use only response.writes to build the whole page, including
the <html> tag etc. (This is a very bad idea).

Finally, use the new fangled way of doing things, and add bits to parts of
the page

eg.
Webpage
<div runat="server" id="theBitToAddStuffTo>
</div>

codebehind
protected withevents theBitToAddStuffTo as System.Web.UI.GenericHTML

theBitToAddStuffTo.innerHTML=theBitToAddStuffTo.in nerHTML+"Some Stuff"

There are I suspect even more, possibly better ways to do it

ME
--
Martin Eyles
ma**********@NOSPAM.bytronic.com
Nov 19 '05 #8

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

Similar topics

9
by: Ricardo | last post by:
Hi. How should I pass a " (doble-quote) character to response.write() in order for it to be sent to the output ? Thanks in advance for the help.
0
by: Copa | last post by:
Hello, I am testing buffering an asp page and Flushing information out to the browser, hence i wrote the code in an asp page that follows this Message Post. The loops are suppose to simulate...
2
by: Rob McLennan - ZETLAND | last post by:
Hi, I'm relatively clueless when it comes to correct ASP syntax. I'm testing out a search form for my company's website which is done in ASP. The results are displayed as per the code shown at the...
3
by: Gary | last post by:
I am having a strange problem that I cannot solve. I have an asp page that I use for a user to login and gain access to other pages. When the user logs in I set a couple of session variables like...
9
by: Dominic Godin | last post by:
Hi, I have an asp page that does a lot of processing and reports it's finished by printing the word "Success". For example: <% SomeFunction(SomeVar) SomeFunction(SomeVar1) ...
13
by: TinyTim | last post by:
I'm a newbie at ASP & HTML. It seems that when you use server side code and you're going to return a customized HTML form with several fields and labels, you have to do an extensive amount of...
5
by: Luiz Vianna | last post by:
Guys, I need to send some info to my client while I'm processing some stuff. The flow will be something like : -process -response -process -response .... I imagine to use response.flush...
0
by: jose.mendez22 | last post by:
I'm trying to fire a pop-up window before I execute a lengthy stored procedure so I may utilize this window as a status window on number of records executed. After my response.write statements...
6
by: john | last post by:
The standard method to transmit a file from an aspx page to a browser is to stream the file to the response then end the response. The HTML code generated by the aspx page is discarded, and the...
4
by: cbtechlists | last post by:
I have an ASP app that we've moved from a Windows 2000 to a Windows 2003 server (sql server 2000 to sql server 2005). The job runs fine on the old servers. Part of the app takes a recordset and...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.