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!
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>")
Re: Javascript Conditional Popup Window Open
You could also use Page.RegisterStartupScript() with your javascript string there.
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
Re: Javascript Conditional Popup Window Open
Use vb:
VB Code:
Private Sub ibtEnter_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtEnter.Click
If ValidateFields() Then
MessageBox("Im Okay")
End If
End Sub
VB Code:
Private Sub MessageBox(ByVal sMessage As String)
'Do not send message strings that include an apostrophe
sMessage = "<script>" + "alert('" + sMessage + "');" + "</script>"
Page.RegisterStartupScript("ClientSideScript", sMessage)
End Sub
Re: Javascript Conditional Popup Window Open
Kewl, Wild_Bill - thanks!