response.write question

E

EMW

Hi,

When I use
Response.Write "something"
it is placed at the top op de html document above the <HTML> tag.
I need it to be put in the BODY part.

How can I do this?

rg,
Eric
 
K

Kevin Spencer

Well, you've got 2 choices:

1. Use ASP (looks like what you're used to)
2. Learn ASP.Net's Object-oriented programming model.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
S

Steve C. Orr [MVP, MCSD]

Response.Write is almost never used any more, mainly because of the reason
you pointed out.

Instead you should probably use a Label control, a PlaceHolder control, or
some other control, since they can be placed precisely at design time.
Then you can set it from your code behind like this:

Label1.Text="Whatever"
 
B

Brock Allen

Response.Write is ver much against the entire zen of ASP.NET's object model.
Sure, use it for debugging (though Trace.Write is much better), but you shouldn't
be using it for rendering your page. If you want something to be added to
your page, put a <asp:Label runat=server id=_myInfo /> (or some other server
side control) and set the _myInfo.Text proeprty to the string you want visible.
This is a higher level object model that's very different than classic ASP.
It's definetly different, but a much more productive model once you get used
to it.
 
T

Tom wilson

This might make more sense and this is what I do.

Create a new aspx page and at the top put a PlaceHolder control. Call
it something like PH1. Next, you need to append your page content to
the pageholder. So lets say the first thing on the page is a heading:

Dim T1 as New LiteralControl
T1.Text = "<FONT Face = ""Arial"">This is my heading</FONT>"
T1.ID = "T1" ' Optional
PH1.Controls.Add(T1)

Dim B1 as new Button
B1.Text = "Submit"
B1.ID = SomeVal
PH1.Controls.Add(B1)

When this page is loaded you'll get a heading and a button below it.
For more complex pages with tables an so on I typically define strings
like:

TableStart as String = "<TABLE><TR><TD>"
MyContent as String = "<DIV Align=Center>My Content!</DIV>"
TableEnd as String = "</TD></TR></TABLE>"

I then define 3 LiteralControl's, assign the text to them and add them
in order to the placeholder. I found this method much more flexible
for inserting error texts into the page (actually into the placeholder
order). I use response.write only for temporary debugging messsages.
You can also visually design a skeleton of your page and put
placeholders where you want dynamic content to appear. I recently did
an entire aspx page of nothing but dynamically created controls and
content. It works very well.

Pardon any errors above but it's a better answer than 'rtfm'. ;)
 
M

Matt Berther

Hello Kevin,

And this response helped how?

In the time that it takes to come off with an answer like this, why not construct
an answer that may remotely help the original poster?
 
K

Kevin Spencer

And this response helped how?

I have no idea. A response can help, but it is up to the receiver to make it
help. A doctor can prescribe medicine, but if the patient doesn't take it,
the patient doesn't get well.
In the time that it takes to come off with an answer like this, why not
construct an answer that may remotely help the original poster?

Well, now, if I were a doctor, and someone came into my office with a cough,
I suppose I could give them some cough syrup and send them on their merry
way. Somehow I get the feeling that this is what you would do. A GOOD doctor
would examine the patient, determine the disease that is causing the
symptoms, and prescribe some medicine that would kill the disease, not
simply make the patient stop coughing.

In this case, my self-appointed Mentor, I diagnosed that the poster had
virtually no experience with Object-oriented programming, and was trying to
work with technology that he was almost completely unfamiliar with. How did
I diagnose this? Well, I read between the lines. Wish I could explain the
technique to you, but it requires some abstract thought to comprehend.

I could have given him some cough syrup and sent him on his merry way. My
conscience wouldn't allow me to do that. So, I risked your wrath, and the
wrath of all the other self-appointed judges out there, and told him what he
needed to hear, not necessarily what he wanted to hear. Sue me.

BTW, how much did your post help him? Or did you just want to be recognized
as a beacon of compassion in a coldly logical world?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
T

Tom wilson

I could have given him some cough syrup and sent him on his merry way. My
conscience wouldn't allow me to do that. So, I risked your wrath, and the
wrath of all the other self-appointed judges out there, and told him what he
needed to hear, not necessarily what he wanted to hear. Sue me.

So the better solution is 'rtfm'? I'm sure he's out there buried in
textbooks for weeks trying to figure out what I gave him in 3
paragraphs. I asked the same question once. I got a reply like yours
which was 100% useless and a small code example like the one I
provided. I had my pages working in hours.

Anyone can say read the manual. Knowledgable people answer his
question.
 
S

StephenRichter

Tom said:
This might make more sense and this is what I do.

Create a new aspx page and at the top put a PlaceHolder control. Call
it something like PH1. Next, you need to append your page content to
the pageholder. So lets say the first thing on the page is a heading:

Dim T1 as New LiteralControl
T1.Text = "<FONT Face = ""Arial"">This is my heading</FONT>"
T1.ID = "T1" ' Optional
PH1.Controls.Add(T1)

Dim B1 as new Button
B1.Text = "Submit"
B1.ID = SomeVal
PH1.Controls.Add(B1)

When this page is loaded you'll get a heading and a button below it.
For more complex pages with tables an so on I typically define strings
like:

TableStart as String = "<TABLE><TR><TD>"
MyContent as String = "<DIV Align=Center>My Content!</DIV>"
TableEnd as String = "</TD></TR></TABLE>"

I then define 3 LiteralControl's, assign the text to them and add them
in order to the placeholder. I found this method much more flexible
for inserting error texts into the page (actually into the placeholder
order). I use response.write only for temporary debugging messsages.
You can also visually design a skeleton of your page and put
placeholders where you want dynamic content to appear. I recently did
an entire aspx page of nothing but dynamically created controls and
content. It works very well.

Tom, this answer helped me a lot. Just like the original poster, I did
not know how to write dynamic content to the page. Thanks!

-Steve
 
K

Kevin Spencer

Did I tell him to "read the manual?"

Glad you got your stuff "working." So, why are you still here? Perhaps you
didn't advance your knowledge, and still need someone to do your fishing for
you?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
K

Kevin Spencer

BTW, Tom, if you don't like the advice, ignore it. If you think you have
better advice to give, then give it. What advice I give is none of your
business. Or are you the self-appointed guardian of the Internet?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
M

Matt Berther

Hello Kevin,

First of all, dont tell me what you think I would do. My track record in
this newsgroup and the others I participate in speaks for itself. I much
prefer to point people towards a solution rather than providing a ready made
one. You know, teach a man to fish...

Listening to you though, it would appear that you think you are the only
GOOD person in this newsgroup. Most everyone else does not have a problem
putting forth a simple solution to help out and directing the poster to additional
information if they feel it necessary.

You know, a majority of the people posting questions in this newsgroup probably
do not understand the fundamentals of OOP. Why not just make it a prerequiste
that they master these fundamentals prior to asking a simple question?

Need to know how to do something with ASP.NET? Learn the intricacies of Object
Oriented Programming first.
Need to know how to make a line of text end up in the <body> section? Before
we do that, why dont you master the principles of inheritance, polymorphism
and encapsulation.

Give me a frickin break...

As far as my post helping the original poster... Perhaps you failed to realize
in your god-like state that I was responding to you and your condescending
tone. I'm still baffled that an MVP can conduct him/herself in this manner
in a Microsoft sponsored public forum.
 
E

EMW

Thanks Tom.

Also thanks for those in this thread who tried to help.

As for the ones having a discussion on how to answer a message....take it to
another newsgroup.

Tom,

I am trying to add a <MAP MAP="map1"><AREA .....><AREA.......></MAP> section
to my aspx page.
AS I understand your example, I should just use a placeholder, somewhere on
the page?

rg,
Eric
 
E

Eliyahu Goldin

My track record in
this newsgroup and the others I participate in speaks for itself.
Googled newsgroups on "Matt Berther". 687 results.
Googled newsgroups on "Kevin Spencer" asp.net. 4,560 results.
Listening to you though, it would appear that you think you are the only
GOOD person in this newsgroup.
It is irrelevant what Kevin thinks. What is relevant, that his answers are
the most valuable asset of this newsgroup. Note that I don't know Kevin
personally.
Most everyone else does not have a problem
putting forth a simple solution to help out and directing the poster to additional
information if they feel it necessary.
Depends on how much time you have to write answers. What makes you think
that 10 minutes of my time is less valuable than 2 hours of the original
poster's work? And, as Kevin noted, you can always ignore an answer if you
don't like/understand it.

Eliyahu
 
K

Kevin Spencer

Don't you have somebody else's business to mind? I think there's an opening
in Florida.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
G

Guest

Why would you use a literal control for this? Wouldn't a better solution be
to an HtmlTable and add that to the place holder. Creating strings for your
html really reeks of someone who moved up to asp .net from asp and still
doesn't know what they're doing.
 
E

EMW

I moved from nothing (with a little knowledge of html and still growing
experience of vb.net) to ASP.NET.
 
E

EMW

YES!!!

got it working.
The stuff I wanted to put in is now where it should be.

Thanks for the help, Tom!
rg,
Eric
 
T

Tom wilson

He was referring to me. I got the literalcontrol method from another
helpful developer and it works very well. I don't have time to sift
though MS's 300,000 line 'simple' examples to find the most
complicated method of doing things.

I find far more flexibility to define my table segments as literals
than to use MS's table control. For the same reason I don't bind my
controls directly to data sources. Too many restrictions and too much
work to get around them. I mostly create my page frameworks in design
view and stick placeholders in where I need dynamic content and append
controls and data from there.

Use whichever method you prefer. A MS table control works great for
simple stuff. Play around with placeholders and adding controls,
you'll get the picture right away. If it were me I'd either add the
map definitions in design view or add them as literals before the end
body tag. But that's me. :) I do what works.

Tom
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,090
Latest member
ActivlifeKetoDiet

Latest Threads

Top