0

I'm having a problem with this code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    clave = Request.QueryString("cve")

    If clave = Nothing Then
        Response.Write("<script language='javascript'>alert('Querystring is empty');window.close();</script>")
        Return
    End If

    Dim valid As Boolean
    valid = Regex.Match(clave, "\b\d{3}\-\d{3}\-\d{3}\b").Success

    If valid = False Then
        Response.Write("<script language='javascript'>alert('Wrong format');window.close();</script>")
        Return
    End If

'More Code
End Sub

The thing is that, the first if statement works fine and the 'javascript' shows an alert and close the window, but in the second if statement the javascript shows the message but doesn't close the window.

Do you guys know how to fix this?

Eduardo Rascon
  • 693
  • 1
  • 8
  • 17

2 Answers2

1

The code seems fine.

Try to use Client.RegisterScriptBlock instead.

Guilherme Duarte
  • 3,371
  • 1
  • 28
  • 35
1

window.close(); is correct, but for security reasons, most browsers won't let you close windows you didn't open.

nitro2k01
  • 7,627
  • 4
  • 25
  • 30
  • I'm using Chrome 10, but I dont thing thats the problem, beacuse the window.close in the first Response.write does work. – Eduardo Rascon Mar 24 '11 at 19:55
  • Might want to check these: http://stackoverflow.com/questions/760422/how-can-i-close-a-window-with-javascript-on-mozilla-firefox-3 and http://forums.asp.net/t/1264584.aspx – gbs Mar 25 '11 at 02:04