ASP.NET: Open a popup window on first load only?

I need to popup a window when a user successfully logs into my application.

I do not want the popup to open every time they navigate to a page in the application, so I can not put it in the master page.

What is the best way to do this?

So far the best I can think is to pass a query string like firstlogin=true and check that on the master page, and if true, then popup the window? Is there an easier way of doing this?
HADDADD3Asked:
Who is Participating?
 
Tom BeckCommented:
Just paste this directly into a script block on the page somewhere as a test. Are you sure you don't have popups blocked in your browser? Pop up windows are a bad idea these days. Too many users block them.

newwindow=window.open(""http://www.google.com"",""name"",""height=200,width=150"");if (window.focus) {newwindow.focus()}
0
 
Tom BeckCommented:
I'm assuming you mean popup window, but an alert of confirm box would works as well. In Page_Load you could register the pop up javascript and put it in a IsPostBack conditional so it only runs on the initial load.

If Not IsPostBack then
    Dim myScript As String = "newwindow=window.open(""http://www.mydomain.com"",""name"",""height=200,width=150"");if (window.focus) {newwindow.focus()} return false;"
        ClientScript.RegisterClientScriptBlock(Me.GetType(), "myPopUp", myScript, True)
End If
0
 
dexterrajeshCommented:
the other option would be like pop-up an window using javascript window.open(.....) after the login validation is successful for the user before redirecting to the application home page... you can use the Literal control and set the javascript script strings to that...

all this has to be done in the Login content page where you do the validation for user login..

hope this helps...
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
dejaanbuCommented:
you can have a flag field in your login table. once a person logins, you can put a flag on that field. so if that flag is false, this is the first time for that user.. likewise, you can check...your idea  also seems okay.
0
 
HADDADD3Author Commented:
TommyBoy,

Sometimes the page will post back, it is a master page for the entire users area...

The redirect for the login is done from the server side, can i still call it from there?
0
 
HADDADD3Author Commented:
TommyBoy,

Tried your solution, and it did not work, popup did not open...
0
 
Tom BeckCommented:
Sorry for the delay in replying, very busy today.

The "return false" should not have been there. It can be made to work from the Master page codebehind but since the master page does not inherit from "Page" you need to add the Page namespace before the ClientScript namespace. Personally, I would put the script in the code behind of the appropriate content page just to have more control over placement, but it will work either way. Here's the corrected code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim myScript As String = "newwindow=window.open(""http://www.google.com"",""name"",""height=200,width=150"");if (window.focus) {newwindow.focus()}"
            Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "myPopUp", myScript, True)
        End If
    End Sub
0
 
HADDADD3Author Commented:
Still no luck...And i have it on a content page...
0
 
HADDADD3Author Commented:
Did it as a in page popup
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.