ASP.NET:每5分钟从代码后面调用一次弹出窗口

ASP.NET: Call Popup Window every 5 minute from code behind

本文关键字:一次 窗口 调用 NET 5分钟 代码 ASP      更新时间:2024-01-07

我是ASP.NET 的新手

我想实现每5分钟调用一次弹出窗口的页面。

在app_code中,我实现了一个调用弹出窗口的类。

我想每5分钟调用一次popup,所以每次都用随机方法更改RegisterStartupScript的键。

public class Ad
{ 
...blah blah...

    public static void CallPopup(Page pageInstance)
    {
        Random r = new Random();
        string key = "popupScript" + r.Next();
        ClientScriptManager scriptManager = pageInstance.ClientScript;
        string script = "<script>window.open('../PopUp.aspx', 'popup_window',
                        'width=400, height=300, scrollbars=yes');</script>";
        scriptManager.RegisterStartupScript(pageInstance.GetType(), key, script);
    }
...blah blah...
}

并在.aspx.cs中使用,如此

public partial class WebAdPage: System.Web.UI.Page
{
..blah blah..
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        adObj.CallPopup(this);
    }
.. blah blah ..
}

但调用弹出窗口只是第一次工作。

它不是每5分钟工作一次。

我的代码出了什么问题?

请给我一些建议或链接。

提前谢谢。

请检查以下内容:参考:http://forums.asp.net/t/1563462.aspx

function OpenWindow()
{
// write open popup window code.
}
setinterval("OpenWindow();", 300000);
it will open window every 5 min

and  on popup window you can also call the js function 

function CloseWindow()
{
// write self close.
}
setTimeout("CloseWindow();", 60000);  // one minute.

我为自己找到了解决方案。

这个问题的关键是在哪里添加脚本。

在我的情况下,当更新面板自我更新时,调用弹出窗口。

要实现这一点,请将脚本附加到updatePanel部分。

如何做到这一点如下。

将UpdatePanel控件的参数和UpdatePanel控件类型设置为RegisterStartupScript。

string script = "<script>window.open('../PopUp.aspx', 'popup_window',
                'width=400, height=300, scrollbars=yes');</script>";
ScriptManager.RegisterStartupScript(updateObj, updateObj.GetType(), key, script, false); 

这将是一个很好的工作。

http://helpondesk.blogspot.kr/2008/11/how-to-register-client-script-inside.html