RegisterStartupScript只在部分时间工作

本文关键字:时间 工作 RegisterStartupScript | 更新日期: 2023-09-27 18:22:48

我有一个方法,可以从Web服务中提取html,并在一系列弹出窗口中显示这些信息。为了实现这一点,我编写了一个javascript来创建弹出窗口:

function dynamicPopup(title, HTMLstring) {
    newWindow = window.open();
    newDocument = newWindow.document;
    newDocument.write(HTMLstring);
    newDocument.title = title;
};

I对从Web服务返回的每个对象调用以下内容的结果进行循环。

Page.ClientScript.RegisterStartupScript(this.GetType(), DateTime.Now.ToString(), resultMessage, true);

问题是,当只返回几个弹出窗口时,它是有效的,但如果返回15个,则只显示其中约8-10个。

作为绷带,我在RegisterStartupScript之后添加了一个Wait,这似乎很有效,但会导致交付时间变慢。有人知道解决这个问题的其他方法吗?

RegisterStartupScript只在部分时间工作

我建议您使用Guid来识别带有密钥的脚本

Guid.NewGuid().ToString()

所以

Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), resultMessage, true);

与其在循环中调用多个Page.ClientScript.RegisterStartupScript,不如先构造需要运行的脚本(例如,使用StringBuilder,组合多个用";"分隔的resultMessage),然后只调用Page.ClientScript.RegisterStartupScript一次以执行生成的字符串。