我如何从循环中'写字'字符串... [英] How can I 'writeline' a string from a loop...

查看:75
本文介绍了我如何从循环中'写字'字符串...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我想让用户使用他们所在的.aspx页面,同时从''while循环'开始进行

a过程:


而不是resultint = 0

代码......

Label1.Text.WriteLine(ntime)

结束时


感谢帮助。

谢谢,

Trint


..Net程序员
tr********@hotmail.com


***通过开发人员指南 http://www.developersdex.com ***

不要只是参加USENET ......获得奖励!

Trint ,


a System.WEb.Ui.Webcontrols没有一个writeline方法。 ..


第二..你想使用响应对象,并使用response.write

方法来做你想做的事。 />

现在......它不仅仅是那个简单。为什么?因为response.write将

在开头写出所有数据(在发送渲染状态之前

你的任何其他控件...所以你会有一堆最丑的文字在

顶部,然后在你的页面下面...可能不是你想要的。


最好的解决方法是使用IFrame对你的页面的其余部分没有任何影响,并允许你自定义一个实时进度条

概念...


有些人可能会说只是覆盖渲染方法。没有......不能这样做因为

它将被缓冲,这只会处理迭代...好好形成它,

然后只在所有渲染完成后刷新缓冲区,

击败整个目的......


HTH,

CJ


" Trint Smith" tr ******** @ hotmail.com>写道:消息

新闻:%2 **************** @ tk2msftngp13.phx.gbl ... 好的,我想让用户使用他们所在的.aspx页面,同时从''while循环'开始进程:
虽然不是resultint = 0
代码......
Label1.Text.WriteLine(ntime)
结束时

非常感谢帮助。
谢谢,
Trint

.Net程序员
tr **** ****@hotmail.com

***通过Developersdex发送 http://www.developersdex.com ***
不要只是参加USENET ......获得奖励!



CJ泰勒,我知道你的写作是正确的,但是这里有点

我在你正在谈论的那个函数中需要什么


Dim dt1 As DateTime = DateTime.Parse(" 2/18/04 06:00 AM")

Dim dt2 As DateTime = DateTime。 Parse(< 2/17/04 07:53 PM")

D. im nowdatetime As DateTime =

DateTime.Parse(System.DateTime.Now)


Dim timezero As Integer

timezero = String 。比较(dt1,nowdatetime)

虽然不是timezero = 0

timezero = String.Compare(dt1,nowdatetime)

Dim span As TimeSpan = nowdatetime.Subtract(dt2)

Label2.Text = span

结束时


.Net程序员
< a href =mailto:tr ******** @ hotmail.com> tr ******** @ hotmail.com


***通过开发人员指南 http://www.developersdex.com 发送***

不要只是参加USENET ......获得奖励!


Trint,


Trint Smith < TR ******** @ hotmail.com>在留言中写道


1)^^^你收到很多垃圾邮件吗?


新闻:O0 ***** ********* @ TK2MSFTNGP11.phx.gbl ...

CJ泰勒,我知道你写的是正确的,但这里有点
我是什么需要你正在谈论的功能

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)
虽然不是timezero = 0
timezero = String.Compare(dt1,nowdatetime)
昏暗的跨度正如TimeSpan = nowdatetime.Subtract(dt2)
Label2.Text = span


所以,就在这里你会得到

Response.Write(span )

当循环结束并且控件失去其范围时流将是

关闭。 (除非你确定你知道你在做什么,否则不要使用Response.Close。

过早关闭它会导致运行时错误。)


但是就像我说的那样,它把它放在顶部...所以在你的

页面的代码中,你需要包含一个IFrame标签,它将位于页面的某个位置

,就像一个单独的浏览器。这个IFrame将有源链接

/yoursite/yourcounter.aspx


这样,它可以继续直接将流写入浏览器窗口

以更漂亮的方式。然而,这打破了良好的设计模式,因为你没有将表示逻辑与业务逻辑分开(好吧,不是我们都想到的那种方式)。


但是除非你做一次定时刷新,否则它是唯一的方法,而且我不会建议你这么做。


-CJ

结束时

网络程序员
tr ********@hotmail.com

***通过Developersdex发送 http://www.developersdex.com ***
不要只是参加USENET ......获得奖励!



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
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!

解决方案

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

"Trint Smith" <tr********@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

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
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!



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
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!


Trint,

"Trint Smith" <tr********@hotmail.com> wrote in message

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

news:O0**************@TK2MSFTNGP11.phx.gbl...

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
End While

Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!



这篇关于我如何从循环中'写字'字符串...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆