Response.write and Contentplaceholder - Howto

M

mosscliffe

I am an old programmer, but a newbie to Visual Web Developer 2005 -
Express Edition

I have an .aspx Form Page with an attached Master File and an attached
css file.

I have scanned a text file for various matching records and output the
ones I want
to display with

response.write(linefound & "<BR>" & vbcrlf)

It all works a treat, BUT all the output appears before the HTML of the
generated web page. If you view source of page - there is all your data
sat before the first valid HTML page tags. Strangely it does display,
but obviously not where I hoped it would go. The output is a result of
clicking a button on the ContentplaceholderForm. The same thing
happens with a simple "Hello World".

How do I get the output from my response.write into the appropriate
ContentPlaceHolder as I have more than one. I do not want to use a
label or a textbox.

Any Help appreciated, as it is now over 24 hours since I slept and I am
nowhere nearer to solving this problem.

Richard
 
F

Flinky Wisty Pomm

Why... don't you want use a label or textbox? If you just call
Response.Write, the string is immediately appended to the response
stream. What you want is to set the value of some element which will be
rendered at Page_Render.

Response.Write does not exist, forget Response.Write, you had some good
times, some bad times, and she'll never forget you but, dude, it's time
to move on.

If you really want to avoid the <span> wrapping a label, use an
<asp:Literal /> instead.
 
G

Guest

Why don't you want to use a label, that is what they are for. There are very
few reasons why you would ever want to use response.write, If you want to
use something a bit more lightweight then try the literal control, but it
will literally output everything in it's text property, javascript, HTML the
lot.
 
P

Patrice

I would use a label but you can add a LiteralControl to your placeholder if
you prefer.

The whole purpose of ASP.NET is to build server side an object model of your
page (as a tree of controls) that are then rendered to HTML to produce the
final output. Response.write comes out of place with this process producing
its output at the top (before the whole tree is rendered).
 
M

mosscliffe

Thanks for your input.

I dont want to use a label for two reasons.

One I will have to find a mechanism to hide it on first display of the
page as I am using postback to redisplay the page

Two I have embedded lots of <UL> and <LI> into the output stream and it
works very well and I am assuming the tag data would be lost in a
label. The output stream can be over a hundred lines and until I work
out how to do paging, I would prefer it to just sit in the
ContentPlaceHolder. I suppose the real answer is associate my data
possibly in an arraylist(Not got to grips with that yet), with a data
grid, but that is for version 4 !!!!

I do not know about the literal tag.

If you could just give me an example of the actual code to use, I would
be most grateful as there are lots of functions, methods and
properties, that at the moment I have no knowledge of. I have arrived
at this point from GWBasic and Turbo Pascal on a DOS Box, so although I
understand programming, all this Code Behind, Objects and event order
is a steep learning curve.

Thanks again for your prompt replies.

Richard
 
C

Chris Fulstow

Hi Richard,

Try adding a Placeholder control to your form, then dynamically add a
LiteralControl to it at runtime, e.g.:

myPlaceHolder.Controls.Add(New LiteralControl(linefound & "<BR>" &
vbCrLf))

A LiteralControl can just be used as a text container, but in a way
that fits in with ASP.NET's page object model. I come from a standard
ASP (not .NET) background, and agree that not using Response.Write is
quite confusing at first. You shouldn't ever really need to use
Response.Write in ASP.NET, but I find myself cheating quite often,
especially when debugging.

Hope this helps,

Chris
 
F

Flinky Wisty Pomm

Okay, that makes more sense.

I'm sure other people will pop up with bits and pieces, but what if you
tell us what your text file is for and how it's parsed? Then I can
offer you a quick ASP.Net solution rather than working through things
bit by bit.

It sounds like the control you're looking for is the Repeater control,
which essentially gives you the old
<%
For i = 0 to recordCount
Response.Write(...)
Next
%>

functionality but with more powerful templates and the .Net databinding
model.
 
M

mosscliffe

Chris,

Thank you very much I can go to sleep now. It worked perfectly.

Thanks to the others who gave the right answer, but not the example I
obviously needed at my low level of competance.

I will read about LiteralControls when I wake up.

Many thanks again.

Richard (Manchester, UK)
 
C

Chris Fulstow

No problem - one other thing: if you're producing <ul><li>...</li></ul>
lists then it might be worthing looking at the BulletedList control,
which you can bind to a data source. This is .NET 2.0 only, but you
should be fine with Visual Web Developer 2005 Express.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top