Statement cannot appear within a method body. End of method assumed. when a </script> is put on a String

Hi,

I am trying to execute a Javascript code AFTER I do server side processing in ASP.NET. I am using VB.NET as host language.

I have this code in my server side script:

Response.Write("<script language=javascript>window.open( mypage.aspx','mywindow','width=100,height=100')</script>")
     
But for some reason, I get this compilation error...

"Statement cannot appear within a method body. End of method assumed."

I get the same error if I do a RegisterClientScriptBlock.  It seems that I can't put a </script> tag on any string.

Help?





crickpaoloAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

shahprabalCommented:
Looks like you are missing a single quotes before mypage.aspx
Change this :
Response.Write("<script language=javascript>window.open( mypage.aspx','mywindow','width=100,height=100')</script>")
To :
Response.Write("<script language=javascript>window.open( 'mypage.aspx','mywindow','width=100,height=100')</script>")

And try it
0
crickpaoloAuthor Commented:
i tried it, but same error though...
0
shahprabalCommented:
Try :

Response.Write("<script language=javascript>window.open( 'mypage.aspx')</script>")

and also

Response.Write("<script language = ""Javascript"">var win=window.open('mypage.aspx',null,'width=100,height=100','true');</script>")

and see if that works
0
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

crickpaoloAuthor Commented:
nope. same error.
0
shahprabalCommented:
Below are the few functions I had created... see if you have any luck using them...
    Public Function OpenWindow(ByVal strURL As String, ByVal strTitle As String, ByVal boolScrollBars As Boolean, ByVal boolMenuBar As Boolean, _
                                ByVal boolToolBar As Boolean, ByVal boolStatusBar As Boolean, ByVal boolLocationBar As Boolean, _
                                ByVal boolResizable As Boolean, ByVal strHeight As String, ByVal strWidth As String) As String
 
        Dim OpenString As String = "<script language = 'javascript'> " & _
                                 "window.open('" & strURL & "', '" & strTitle & "', " & _
                                 "'scrollbars=" & CStr(boolScrollBars) & ", menubar=" & CStr(boolMenuBar) & _
                                 ", toolbar =" & CStr(boolToolBar) & ", location=" & CStr(boolLocationBar) & _
                                 ", status =" & CStr(boolStatusBar) & _
                                 ", height=" & strHeight & ", width=" & strWidth & _
                                 ", resizable=" & CStr(boolResizable) & "');</script>"
        Return OpenString
    End Function
 
    Public Function OpenWindow(ByVal strURL As String, ByVal strTitle As String) As String
 
        Dim OpenString As String = "<script language = 'javascript'> " & _
                                 "window.open('" & strURL & "', '" & strTitle & "');</script>"
        Return OpenString
    End Function
 
    '   Opens a window with no bars, which cant be resized, only closed
    'window.showModalDialog("http://www.altavista.com","","dialogWidth:500px;dialogHeight:500px") 
    Public Function OpenModalWindow(ByVal strURL As String, ByVal strTitle As String) As String
 
        Dim OpenString As String = "<script language = 'javascript'> " & _
                                 "window.showModalDialog('" & strURL & "', '" & strTitle & "');</script>"
        Return OpenString
    End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
crickpaoloAuthor Commented:
Thanks Shahprabal. Unfortunately, I still get a compilation error.  The compiler simply wont accept a "</script>" tag inside any server side code.

I did find a clever solution on google though. Instead of coding "</script>", code it as "</scr" & "ipt>".  Breaking it down into a composite string seems to fool the Visual Studio compiler to not recognize the reserved word.

I giving you the points though for all your effort. Thanks!
0
shahprabalCommented:
Did you check the target schema for validation in the formating or the html source editing toolbar (by default it should be set to XHTML 1.0)... I am glad you found a workaround though... thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.