Reputation: 199
I'm a newbie on ASP.NET
I want to implement the page which call popup window every 5 minutes.
In app_code, I implemented a class which call popup window.
I want to call popup every 5 minutes, so changed the key of RegisterStartupScript every time by random method.
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...
}
And Use it in .aspx.cs like this
public partial class WebAdPage: System.Web.UI.Page
{
..blah blah..
protected void Timer1_Tick(object sender, EventArgs e)
{
adObj.CallPopup(this);
}
.. blah blah ..
}
But Calling popup window worked only first time.
It dosen't work every 5 minutes.
What's wrong with my code?
Please give me some advice or link about it.
Thank you in advance.
Upvotes: 0
Views: 1659
Reputation: 199
I found the solution for my self.
The Key of this problem is Where to add the Script.
In my case, When the update panel update it self, then call the popup window.
To implement this, attach script to updatePanel part.
How to do this is below.
Set parameters with UpdatePanel control and type of UpdatePanel control to 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);
It would be work well.
http://helpondesk.blogspot.kr/2008/11/how-to-register-client-script-inside.html
Upvotes: 0
Reputation: 5727
Please check below: reference : 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.
Upvotes: 1