Response.Write Problem

M

matthew

Hi all,

I am now writing a aspx that get a session variable (string) and then write
it out using Response.Write.

The string length is: 494710.

But Response.Write only write the string partially!

I tried using following code, but it doesn't work, the page is keep loading.

if(stringcontent.Length > 500)
{
Response.Write(stringcontent.Substring(0,500));
stringcontent = stringcontent.Substring(500);
while(stringcontent.Length > 500)
{
Response.Write(stringcontent.Substring(0,500));
pagecontent = stringcontent.Substring(500);
}
}
Response.Write(stringcontent);

How I can solve it?? Thx a lot.

Matthew
 
A

Ashish M Bhonkiya

Hi matthew,

you should not be storing huge items in session as this can degrade your
performance.

if i see your code it seems like you are not changing the value of
stringcontent variable so its an infinite loop.
while(stringcontent.Length > 500)
{
Response.Write(stringcontent.Substring(0,500));
pagecontent = stringcontent.Substring(500);
}

Regards
Ashish M Bhonkiya
 
M

matthew

sorry, the code should be

while(stringcontent.Length > 500)
{
Response.Write(stringcontent.Substring(0,500));
stringcontent= stringcontent.Substring(500);
}

still doesn't work.

If i don't use session, how i can pass such item from aspx to other aspx?
 
A

Ashish M Bhonkiya

Hi Matthew,

Probably if you use your code it will not display the last part and that is
where the problem is. so you may update your code as follows and it should
work.

while(stringcontent.Length > 0)
{
// this will take care of the length at the last part if it
is not in the multuple of 500.
int myLength = (stringcontent.Length>500) ?
500:stringcontent.Length;

Response.Write(stringcontent.Substring(0,myLength));
Response.Write("<BR>");
stringcontent= stringcontent.Substring(myLength);
}

it was just to make you aware to not unnecessacarily load the server
resources you may go for session variables no issues.
Also you can the data across the form using Using Querystring or Using
Server.Transfer you may read this article for more details
http://www.dotnetbips.com/displayarticle.aspx?id=79

HTH
Regards
Ashish M Bhonkiya
 
M

Matt Berther

Hello Matthew,

And what happens when you do:

Response.Write(stringcontent);
Response.Flush();
 
P

Phill. W

matthew said:
I am now writing a aspx that get a session variable (string) and then write
it out using Response.Write. .. . .
But Response.Write only write the string partially!

matthew,

Does it "break" at any "meaningful" point or just give up after a
certain number of bytes or at a given character in the data (say,
a null character, 0x00 )?

HTH,
Phill W.
 

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

Similar Threads


Members online

Forum statistics

Threads
473,797
Messages
2,569,647
Members
45,378
Latest member
danzeev

Latest Threads

Top