Results 1 to 6 of 6

Thread: Javascript Conditional Popup Window Open

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Question Javascript Conditional Popup Window Open

    Hi ...

    I have an aspx page with VB as the code behind. I want to conditionally open a popup window with Javascript when a button is clicked on the aspx page. For example:

    Code:
    If all checks are okay then
        Open Popup Window with Javascript
    End If
    Is this possible? In the examples I've seen, the window is always opened when the button is clicked.

    Thanks!

  2. #2
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727

    Re: Javascript Conditional Popup Window Open

    Yes, use an if statement like you have done above.

    if checks are ok then u can use the following code

    Response.Write("<script language=javascript>window.open('http://www.google.com',null,'height=200, width=400,status= no, resizable= yes, scrollbars=no, toolbar=no,location=no,menubar=no ');</Script>")

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Javascript Conditional Popup Window Open

    You could also use Page.RegisterStartupScript() with your javascript string there.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Thumbs up Re: Javascript Conditional Popup Window Open

    Thanks guys! Mendhak, in my research, I saw "Page.RegisterStartupScript()" but I didn't see how I could incorporate it with an IF statement to only display the popup if certain conditions were met.

    Thanks again.

    OneSource

  5. #5
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Javascript Conditional Popup Window Open

    Use vb:
    VB Code:
    1. Private Sub ibtEnter_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtEnter.Click
    2.         If ValidateFields() Then
    3.             MessageBox("Im Okay")
    4.         End If
    5.     End Sub
    VB Code:
    1. Private Sub MessageBox(ByVal sMessage As String)
    2.         'Do not send message strings that include an apostrophe
    3.         sMessage = "<script>" + "alert('" + sMessage + "');" + "</script>"
    4.         Page.RegisterStartupScript("ClientSideScript", sMessage)
    5.     End Sub

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Re: Javascript Conditional Popup Window Open

    Kewl, Wild_Bill - thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width