calls and code behind / response.write confusion

G

Guest

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 !!!!!!!!!
 
S

Steve C. Orr [MVP, MCSD]

I'd probably create a control to handle such a task.

Here's more info:
http://msdn.microsoft.com/library/d...n/html/vbconintroductiontowebusercontrols.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vboriwebusercontrols.asp
http://msdn.microsoft.com/library/d...l/vbconWebUserControlsVsCustomWebControls.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net


etropic said:
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.... said:
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.
 
G

Guest

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
 
J

Jeffrey Palermo [MCP]

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 said:
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.... said:
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.
 
G

Guest

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
 

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

Top