New window from dropdown list

  • Thread starter Thread starter Jeff via DotNetMonster.com
  • Start date Start date
J

Jeff via DotNetMonster.com

Hi,

I'm trying to open a new window to bring up an external link once a value
is selected from a drop down list. I'm trying the following but I get the
error:

'If' must end with a matching 'End If'


Sub State_SelectedIndexChanged(sender As Object, e As EventArgs)

If State.SelectedItem.Value="CT" Then
Response.Write("<script>window.open("PageName.aspx")</script>")
End if
End Sub
 
Hello Jeff via DotNetMonster.com,

This may have to do with the quoting issue:

Try:

Response.Write("<script>window.open('PageName.aspx')</script>")

Notice the ' instead of ". I think using VB you can get the " character in
there by using "".

Response.Write("<script>window.open(""PageName.aspx"")</script>")
 
Hello Jeff via DotNetMonster.com,

Are you sure that the line you posted is the one generating the error?
 
Yes. Does anything need to be defined in the header of the page? It looks
like the ending script tag </script> is closing the <script runat="server">
because it doesn't recognize my other function.
This is what I have:

<script runat="server">
Sub State_SelectedIndexChanged(sender As Object, e As EventArgs)
If State.SelectedItem.Value="AK" Then
Response.Write("<script>window.open
(""http://www.eed.state.ak.us/contentStandards/"")</script>")
End If
End Sub

This is the compiler output:
error BC30081: 'If' must end with a matching 'End If'.

If State.SelectedItem.Value="AK" Then
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Inetpub\wwwroot\web\pd\ELLCourses2.aspx(12) : error BC30648: String
constants must end with a double quote.

Response.Write("<script>window.open
(""http://www.eed.state.ak.us/contentStandards/"")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Inetpub\wwwroot\web\pd\ELLCourses2.aspx(182) : error BC30451: Name
'GetLinks' is not declared.

target.DataSource = CType(GetLinks(),Object)
~~~~~~~~
C:\WINNT\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\root\
54f85d9e\82f89da3\v4gskhug.0.vb(424) : error BC30289: Statement cannot
appear within a method body. End of method assumed.

Public Sub New()
~~~~~~~~~~

Thanks so much
 
Hello Jeff via DotNetMonster.com,

I think your assumption that the </script> portion of your Response.Write
is closing the wrong tag is correct. Unfortunately, VB is not my primary
language, so Im just making some guesses here:

1. Is the entire contents of the Response.Write on the same line?
2. Do you get the same error when you replace the "" with ' (ie: Response.Write("<script>window.open('http://www.eed.state.ak.us/contentstandards/')</script>")
 
Back
Top