How to call a Javascript function in VB?

  • Thread starter prince -=nore=-
  • Start date
P

prince -=nore=-

I'm trying to open a new window when a button is clicked.
I'm using the following code in my page_load to do so.




Dim myScript As String = "<script language=javascript> function
loadWin() {"

myScript += "window.open('testl.aspx')"

myScript += "}</" + "script>"

Page.RegisterStartupScript("OpenWindowScript", myScript)




What I want to know, is how to refer or call that function in VB.
 
S

Steve C. Orr [MVP, MCSD]

You could use RegisterStartupScript to ensure your client side function gets called as soon as the page loads into the browser.

Here's more info:
http://msdn.microsoft.com/library/d...mWebUIPageClassRegisterStartupScriptTopic.asp


But you cannot call a client side function directly from server side code.



You can use a bit of HTML like this to link your client side code with a client side event:

<BUTTON id="mybutton" onclick="loadWin"

name="mybutton" type="button" value="Button">

Click Me</BUTTON>


Here's information on how to do that dynamically:
Attributes.Add:
http://www.flws.com.au/showusyourcode/codeLib/code/NET_jsAddTo.asp?catID=5
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,153
Latest member
NamKaufman
Top