How can I 'writeline' a string from a loop...

T

Trint Smith

Ok, I want to let the user use the .aspx page they are on while there is
a process going on from a 'while loop':

while not resultint = 0
code......
Label1.Text.WriteLine(ntime)
end while

Help is appreciated.
Thanks,
Trint

..Net programmer
(e-mail address removed)
 
C

CJ Taylor

Trint,

Ok, you need to understand how response buffering works in asp.net. Now, I
have to admit, I appreciate you creativity with the WriteLine and all... but
a System.WEb.Ui.Webcontrols does not have a writeline method...

Second.. you want to use the response object, and use a response.write
method to do what you want to do.

Now... its not just "that" simple. Why? Because the response.write will
write out all the data in the beginning (before sending the rendered state
of any of your other controls.. so you will have a bunch of ugly text at
the top and then your page below it... probably not what you want.

The best way around this is to use an IFrame which will have no affect on
the rest of your page and allow you to customize a "live progress bar"
concept...

Some may say "just override the render method". Nope... can't do so because
it will be buffered, which will just process the iteration... well form it,
and then flush the buffer only AFTER all the rendering has been done,
defeating the whole purpose...

HTH,
CJ
 
T

Trint Smith

CJ Taylor, I knew you were right about the writeline, but here's kinda
what I need in that function you are talking about:

Dim dt1 As DateTime = DateTime.Parse("2/18/04 06:00 AM")
Dim dt2 As DateTime = DateTime.Parse("2/17/04 07:53 PM")
Dim nowdatetime As DateTime =
DateTime.Parse(System.DateTime.Now)

Dim timezero As Integer
timezero = String.Compare(dt1, nowdatetime)
While Not timezero = 0
timezero = String.Compare(dt1, nowdatetime)
Dim span As TimeSpan = nowdatetime.Subtract(dt2)
Label2.Text = span
End While

.Net programmer
(e-mail address removed)
 
C

CJ Taylor

Trint,


1) ^^^ you get a lot of junk mail dont you?

CJ Taylor, I knew you were right about the writeline, but here's kinda
what I need in that function you are talking about:

Dim dt1 As DateTime = DateTime.Parse("2/18/04 06:00 AM")
Dim dt2 As DateTime = DateTime.Parse("2/17/04 07:53 PM")
Dim nowdatetime As DateTime =
DateTime.Parse(System.DateTime.Now)

Dim timezero As Integer
timezero = String.Compare(dt1, nowdatetime)
While Not timezero = 0
timezero = String.Compare(dt1, nowdatetime)
Dim span As TimeSpan = nowdatetime.Subtract(dt2)
Label2.Text = span

So, right here you would have
Response.Write (span)


When the loop ends and the control loses its scope the stream will be
closed. (Don't use Response.Close unless you sure you know what your doing,
shutting it too early will cause a runtime error.)

However, like I said, it puts it at the top... so in your code for your
page, you need to include an IFrame tag, that will sit somewhere on the page
and act like a separate browser. This IFrame will then have the source link
of /yoursite/yourcounter.aspx

this way, it can continue to directly write the stream to the browser window
in a more pretty fashion. This however breaks good design patterns because
you are not separating presentation logic from business logic (well, not the
way we all think of it).

But its the only way to do so unless you do a timed refresh, and I don't
recommend that.

-CJ
 
T

Trint Smith

CJ,
Believe it or not, I don't get a lot of unwanted email.
Ok, I'm still not completely understanding this...do I put that while
loop in another .aspx file and then display it where I want it on the
page with this? Also, (please),a 'Dim span As TimeSpan =
nowdatetime.Subtract(dt2)' cannot be displayed in a label control
because it can't be converted into a string. What control do I display
the timed countdown with?? I have to take my wife to see her aunt for
two hours and will be right back to do this.
Thank you for your help...
Trint

..Net programmer
(e-mail address removed)
 
C

CJ Taylor

Trint Smith said:
CJ,
Believe it or not, I don't get a lot of unwanted email.

Man those spam filters are good...
Ok, I'm still not completely understanding this...do I put that while
loop in another .aspx file and then display it where I want it on the
page with this?

yes.. that new aspx page goes in your new IFrame.

Also, (please),a 'Dim span As TimeSpan =
nowdatetime.Subtract(dt2)' cannot be displayed in a label control
because it can't be converted into a string.

Forget about the labels... your not going to use labels.

You will have,

Response.write (span.toString())

What control do I display
the timed countdown with??

No control, you write directly to the response stream........
I have to take my wife to see her aunt for
two hours and will be right back to do this.

Ok.... um, good luck with that.
 
T

Trint Smith

I don't know how else to display a string on an aspx page without a
control. Can you tell me that? And I do appreciate your information.
Thanks,
Trint

Net programmer
(e-mail address removed)
 
T

Trint Smith

Ok, I have an Iframe on my page (itemdetail.aspx) where I want it with
it viewing another page (iframe.aspx).
Where do I put the 'while' loop (which aspx file?) and how do I display
the output, is it like at the top left of iframe.aspx and can I put the
code in iframe.aspx.vb here:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
code here?
End Sub

Thanks,
Trint
.Net programmer
(e-mail address removed)
 
C

Cor

Hi Trint and CJ,

I was curious if I could do it.

It is a webclock with full serverside aspx

Not the problem from Trint but to let a serverside status go on the
clientside.

I asking myself if you will be happy with it, but it works.

I have used a clock, it will it give of course in the regional settings
notation from the serverside, while when Trint want to use as a solution for
his problem, I think that he minimal has to add something as cookies in the
second page to identify the startstatus and endstatus of the client who ask
again and again that image.

But I am a little bit proud on this sample, so I show it you (I think I can
make that bitmap nicer but maybe I replace it with a real classic clock, I
think that is even nicer)..

Cor

\\\Form 1 Needs an imagebox on the page the project should be named
"WebClock".
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.Image1.Height = New Unit(32)
Me.Image1.Width = New Unit(200)
Image1.Visible = True
Dim scriptString As String = "<script language=JavaScript>" & _
"setclock(); function setclock(){document.images.Image1.src = " & _

"'http://localhost/WebClock/WebForm2.aspx';setTimeout('setclock()',1000)}</s
cript>"
Page.RegisterStartupScript("setclock", scriptString)
End Sub
///
\\\Form2 needs nothing
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim myForeBrush As Brush = Brushes.Black
Dim myFont As New Font("Times New Roman", 8, FontStyle.Regular)
Dim textHeight As Single
Dim bm As New Bitmap(120, 20)
Dim g As Graphics = Graphics.FromImage(bm)
g.Clear(Color.White)
Dim textSize As SizeF = g.MeasureString("now.tostring", myFont)
g.DrawString(Now.ToString, myFont, myForeBrush, _
New RectangleF(0, 0, 120, 20))
Dim ms As New IO.MemoryStream
Dim arrImage() As Byte
bm.Save(ms, Imaging.ImageFormat.Bmp)
arrImage = ms.GetBuffer
Response.BinaryWrite(arrImage)
End Sub
///
 
T

Trint Smith

Cor,
That does look nicely...but it isn't counting down. How can I get it to
count down though from this code?:

Dim dt1 As DateTime = DateTime.Parse("2/18/04 06:00 AM")
Dim dt2 As DateTime = DateTime.Parse("2/17/04 07:53 PM")
Dim nowdatetime As DateTime =
DateTime.Parse(System.DateTime.Now)

Dim timezero As Integer
timezero = String.Compare(dt1, nowdatetime)
While Not timezero = 0
timezero = String.Compare(dt1, nowdatetime)
Dim span As TimeSpan = nowdatetime.Subtract(dt2)
End While

.Net programmer
(e-mail address removed)
 
T

Trint Smith

Cor and CJ,
I want to show the seconds also as it is counting down from:

current date & time
- future date & time
-------------------
time left & counting down

Thanks,
Trint

Net programmer
(e-mail address removed)
 
C

Cor

Hi Trint,

If I see this good, than is that a macromedia swf movie clock and is that
used

Not all to sure but I think that is it.

Cor
 
C

Cor

Hi Trint,

I was first doing it with that code from you, but there are to much errors
in
Dim dt1 As DateTime = DateTime.Parse("2/18/04 06:00 AM")
Dim dt2 As DateTime = DateTime.Parse("2/17/04 07:53 PM")
Dim nowdatetime As DateTime =
DateTime.Parse(System.DateTime.Now)

Dim timezero As Integer
timezero = String.Compare(dt1, nowdatetime)
You do a string compare on date values.

And when this should pass it will never end anymore and counting down.

So correct this first yourself, so hard can this not be, CJ and I cannot
make all of your code.
 

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