while循环内部的ScriptManager.RegisterStartupScript仅在脱离循环后才执行 [英] ScriptManager.RegisterStartupScript inside while loop only executed after breaking out of the loop
问题描述
我的代码后面有一个while循环,我想监视进度,因此,每次进入循环时,我希望页面绘制一些东西(一个点),当循环中断时,我会看到整个进度( scatterplot)我的代码如下:
I have a while loop in my codebehind and I want to monitor the progress, so each time I go into the loop, I wish my page draws something (a point) and when the loop breaks I would see the entire progress (scatterplot) My code is like the following:
while (iter <= Common.maxIter)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "myFunc" + iter.ToString(), "Display()", true);
//doing something else
}
函数Display()每次绘制一个点.我的问题是,仅当我退出while循环后,所有条形才会同时绘制,但在循环过程中没有绘制任何条形... :(我不确定哪里出错了,如果我使用断点,我可以看到每次都执行此代码,只是未在页面上显示.
The function Display() draws one point each time. My problem is, only after I break out of the while loop, all of the bars get drawn at the same time, but none of them is drawn during the loop...:( I am not sure where went wrong, if I use break point and I can see this code gets executed everytime, just not shown on my page.
任何人都知道正确的方法是什么?非常感谢!
Any one knows what should be the correct way of doing this? Many thanks!
推荐答案
此代码为服务器端"代码:
This code is "Server side" code:
while (iter <= Common.maxIter)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "myFunc" + iter.ToString(), "Display()", true);
//doing something else
}
这是客户端"代码:
"myFunc" + iter.ToString(), "Display()"...
ASP.NET的工作方式是通过在服务器端"执行一系列事件,这也称为页面生命周期".您可能已经知道其中一些事件,只是为您提供这些事件的一些示例:PreInit,Init,PreLoad,Load,PreRender,Render和UnLoad.
The way ASP.NET works is by executing a series of events on the "server side" this is also known as "Page Life Cycle". You may already know some of those events, just to give you some examples of these events: PreInit, Init, PreLoad, Load, PreRender, Render and UnLoad.
我想说最常用的是页面加载事件,我想您的代码示例也放置在该方法中.
I would say that the most often used is the Page Load Event, I guess your code sample was place inside that method as well.