Can I run Javascript inside VBScript?

I want to execute a piece of Javascript inside the button click event of a button, then execute some VB code after the Javascript.  The javascript opens a popup window, when the popup window closes, I want a record to be added to the database and display on my form.

Below is my code, followed by the error.

Sub bAdd_Click(ByVal sender As Object, ByVal e As EventArgs)
                                   
                    Dim popupScript As String = "<script language=javascript>window.open('MsgBoxYesNo.aspx', 'CustomPopUp', 'width=200, height=200, menubar=yes, resizable=no')</script>"
                    Page.RegisterStartupScript("PopupScript", popupScript)

 ******add record to DB here*******
End Sub

<asp:Button ID="bAddPatient" runat="server"  OnClick="bAdd_Click"  Text="Add Patient(s)" Height="24px" Width="150px" />

***************error message*********************
Compiler Error Message: BC30648: String constants must end with a double quote.
I also can't switch to design view b/c  the program thinks I have no matching end tag for <script.  I think it's b/c I've embedded the javascript inside the VB script.
jm76Asked:
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.

enwhyseeCommented:
You should most definitely be able to do what you're saying ... registering a javascript script via RegisterStartupScript on VB.NET

Is the VB.NET code above inside a <script> block?

Also, maybe you could split the script string to see if it makes things better. For example:
Dim popupScript As String = "<scri" + "pt language=javascript>window.open('MsgBoxYesNo.aspx', 'CustomPopUp', 'width=200, height=200, menubar=yes, resizable=no')</s" + "cript>"


Check out the following example:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIPageClassRegisterStartupScriptTopic.asp
0
Giant2Commented:
Are you sure you closed all the " and ' ?
I believe but not sure that you must post \' instead of ' in the popupScript.
So something like:
Dim popupScript As String = "<script language=javascript>window.open(\'MsgBoxYesNo.aspx\', \'CustomPopUp\', \'width=200, height=200, menubar=yes, resizable=no\')</script>"
The error seems displaying the closing string char is not recognized or encountered too quick.

Hope this could help you.
Bye, Giant.
0
abbdanCommented:
View the code of the page it generates to see how its listing the JavaScript code.  If you see missing quotes simply add them to your popupscript string.
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

jm76Author Commented:
I changed the popupscript to



Now there are no errors but there is also no popup.  Any ideas?  Very frustrating!

Here's my code..............

Sub bAdd_Click(ByVal sender As Object, ByVal e As EventArgs)

Dim popupScript As String = "<script language=javascript>window.open('MsgBoxYesNo.aspx', 'CustomPopUp', 'width=200, height=200, menubar=yes, resizable=no')</s" + "cript>"
Page.RegisterStartupScript("PopupScript", popupScript)

 ******add record to DB here, which works great*******
End Sub

<asp:Button ID="bAddPatient" runat="server"  OnClick="bAdd_Click"  Text="Add Patient(s)" Height="24px" Width="150px" />

End Sub
0
enwhyseeCommented:
As abbdan pointed out, when you browse to the resulting page and view source, do you see the generated script in there?

0
abbdanCommented:
Looks like clicking the button is not refreshing the page to add the javascript code.

As I understand you will offer the client a page that has a button on it.  When the client clicks the button the page should refresh so that it adds the javascript for the button being clicked to call a CustomPopUp window?  Seems like the user clicking the button only adds the javascript to the html with nothing calling for the javascript to run at load time.  The event has already occured and therefore no action has occured to run the javascript.  
0
jm76Author Commented:
I don't really understand this question  
As abbdan pointed out, when you browse to the resulting page and view source, do you see the generated script in there?

Am I supposed to see generated script in the MsgBoxYesNO.aspx page?

Abbdan you are correct in what I'm trying to accomplish.  Can you think of an alternative way?

I also tried putting the popup window in a function and calling the function but also, nothing happens.  Example....

Dim javaScript As String = "<script language=JavaScript>GetDate('txtEndDate')</s" + "cript>"
          RegisterStartupScript("bAdd_Click", javaScript)
0
abbdanCommented:
If you have Visual Studio.Net click on the HTML tab below the form that has the button or you can edit the form page that has the button using Notepad or your favorite editor.  The code you'll see is the html part of your aspx form and from there you can physically add the javascript code tagged to run when the button is clicked.  I think the problem is that your javascript gets added after you've already clicked the button and so it needs to be in there prior to the button being clicked.
0
jm76Author Commented:
I created a separate Javascript function to open the popupwindow and called it from the button click event.  Works great, but I still have the additional VB code that needs to run.

I tried to call the VB function from inside the javascript (e.g. VBScript:bAdd_Click) but nothing happens.  Is it possible to call VB script from a Javascript function?
0
abbdanCommented:
VB code runs serverside so that when you click your button your client javascript runs first and then the code behind the button runs from the server in that order.  You can still place code behind the button and have the javascript in your html both working with the same button.
0
abbdanCommented:
The event thats triggered when the button is pressed runs the VB codebehind and an additional tag in the html button control triggers the javascript call.
0
abbdanCommented:
I'm interested.
0
Giant2Commented:
Me too.
jm76, where are you?
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
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.