By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

calls and code behind / response.write confusion

P: n/a
Im confused

I want an .aspx page to have a table with my data in it. At first I wrote FillTablew(); in my Page_Load even in the Code Behind file. I had it loop the db etc. and use Response.Write of a bunch of strings. This works great as long as all I want is the results of those Response.Writes

I believe what I REALLY want is to convert those Response.Writes to a str cat in the code behind, and then in the body of my .aspx page to do something like.... <% Label.Text = FillTable() %> . This way I get the table inside the HTML so I can do other things on the page

I couldn't get that to work so I did the Label.Text = GetTable(); from the Page_Load of the Code behind instead

What SHOULD I have done? The response.write executes before html, so it ends up above my html page when the client sees it, so I think that is out. What I don't get is.... is the ONLY way to get the results of a function in code behind back to the .aspx page on screen to make it the result of a text property ? If this is so, is this desirable? If it is, how do I do it without using the Page_Load function? OR... am I suppose to use it that way

I've been looking it up, but I can only find examples that replace the name of a submit button and the like. I guess what I'm looking for is best practice for returning what will be a bunch of HTML code to the ASPX page from c# code behind

thanks !!!!!!!!!
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I'd probably create a control to handle such a task.

Here's more info:
http://msdn.microsoft.com/library/de...ercontrols.asp
http://msdn.microsoft.com/library/de...ercontrols.asp
http://msdn.microsoft.com/library/de...ebControls.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"etropic" <an*******@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.com...
Im confused.

I want an .aspx page to have a table with my data in it. At first I wrote FillTablew(); in my Page_Load even in the Code Behind file. I had it loop
the db etc. and use Response.Write of a bunch of strings. This works great
as long as all I want is the results of those Response.Writes.
I believe what I REALLY want is to convert those Response.Writes to a str cat in the code behind, and then in the body of my .aspx page to do
something like.... <% Label.Text = FillTable() %> . This way I get the
table inside the HTML so I can do other things on the page.
I couldn't get that to work so I did the Label.Text = GetTable(); from the Page_Load of the Code behind instead.
What SHOULD I have done? The response.write executes before html, so it ends up above my html page when the client sees it, so I think that is out.
What I don't get is.... is the ONLY way to get the results of a function in
code behind back to the .aspx page on screen to make it the result of a text
property ? If this is so, is this desirable? If it is, how do I do it
without using the Page_Load function? OR... am I suppose to use it that way?
I've been looking it up, but I can only find examples that replace the name of a submit button and the like. I guess what I'm looking for is best
practice for returning what will be a bunch of HTML code to the ASPX page
from c# code behind.
thanks !!!!!!!!!

Nov 18 '05 #2

P: n/a
perhaps that's my confusion ? why do I need a control at all? custom or built in

I think perhaps I am missing some fundemental understanding of the relation between the aspx and it's code behind file. I was thinking that I should be able to do something like..

<body
This is my web page !! woo hoo
and I love <% GetHobby(); %> !
</body

Thus returning a string to the exact point in my html (aspx page) that I desired it. More specificly, a string that has HTML formatting in it.... my string is an entire HTML tabl

I will check out the link that you provided. thanks

rob
Nov 18 '05 #3

P: n/a
For best practices, definitely read the links that Steve O. provided.
To get your page working, you can still use methods that you used in ASP 3.0
until you are up to speed with the best ASP.NET practices. The Page_Load
event fires before the Render event, so, naturally, a Response.Write() there
will write before the content in the Render method.

To get your content in the correct place, you can put all your
Response.Writes in a function and then call that function inline with the
HTML in the correct place. Then the function will be called at Render time.
This is NOT the ASP.NET best practice, but it'll get you up and running
until you are more familiar with the ASP.NET methodology.

Jeffrey Palermo

"etropic" <an*******@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.com...
Im confused.

I want an .aspx page to have a table with my data in it. At first I wrote FillTablew(); in my Page_Load even in the Code Behind file. I had it loop
the db etc. and use Response.Write of a bunch of strings. This works great
as long as all I want is the results of those Response.Writes.
I believe what I REALLY want is to convert those Response.Writes to a str cat in the code behind, and then in the body of my .aspx page to do
something like.... <% Label.Text = FillTable() %> . This way I get the
table inside the HTML so I can do other things on the page.
I couldn't get that to work so I did the Label.Text = GetTable(); from the Page_Load of the Code behind instead.
What SHOULD I have done? The response.write executes before html, so it ends up above my html page when the client sees it, so I think that is out.
What I don't get is.... is the ONLY way to get the results of a function in
code behind back to the .aspx page on screen to make it the result of a text
property ? If this is so, is this desirable? If it is, how do I do it
without using the Page_Load function? OR... am I suppose to use it that way?
I've been looking it up, but I can only find examples that replace the name of a submit button and the like. I guess what I'm looking for is best
practice for returning what will be a bunch of HTML code to the ASPX page
from c# code behind.
thanks !!!!!!!!!

Nov 18 '05 #4

P: n/a
sounds good..

I started checking out the links. Most of the books I have on asp.net show examples using response.write. It became apparent that they were doing that just to illistrate teh REST of the code, not for the writing of the data

Sounds like that's my biggest problem then, understanding what asp.net is really trying to accomplish

Thanks again :

rob
Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.