Java-script and vb.net

  • Thread starter Thread starter Bart Schelkens
  • Start date Start date
B

Bart Schelkens

Hi,

how can I execute a piece of Java-script after a piece of vb-net-code has
been executed?

Thx
 
Bart Schelkens said:
Hi,

how can I execute a piece of Java-script after a piece of vb-net-code has
been executed?

Thx

javascript should (probably, I don't exactly know what you want to do) execute
on the client-side, and vb.net on the server side. There is NO way to mix execution
on these two platforms. (unless you are prepared to solve some complicated
communication issues)

You CAN use RegisterStartupScript or RegisterClientScript to generate (java)script
from server side code, which can get executed when it finally arrives on the client.

Hans Kesting
 
Hans,

the problem i'm trying to solve is this:

My website consists of 2 frames.
I have a button in Frame1 that checks some things on my database.
According to the result of those checks, I need to refresh my Frame2.
I got some java-script to refresh my screen but I can't get it executed at
the correct time.
And apparently there's no VB.Net code to get the same result.
 
Just use RegisterStartupScript() or even a Literal WebControl to insert your
javascript to refresh frame2.

When your server-side code finished, the browser will reload and case the
scripts to be excuted.

Actually, I think when the page reloads, your frame2 should be refreshed
automatically. If it does not
seems to refresh, try disable the cache and set expire at "page" tag first.
 
I've put this code in a function that I call to register the script :
js = "<script language=JavaScript>"

js &= "function RefreshMainFrame(item){" & vbCrLf

js &= "window.open('homepage.aspx','mainFrame');" & vbCrLf

js &= "}"

js &= "</script>"

RegisterStartupScript("RefreshMainFrame", js)

The script is registered fine, but it doesn't execute.

What did I do wrong?
 
Bart Schelkens said:
I've put this code in a function that I call to register the script :
js = "<script language=JavaScript>"

js &= "function RefreshMainFrame(item){" & vbCrLf

js &= "window.open('homepage.aspx','mainFrame');" & vbCrLf

js &= "}"

js &= "</script>"

RegisterStartupScript("RefreshMainFrame", js)

The script is registered fine, but it doesn't execute.

What did I do wrong?

You specified a function, but didn't call it anywhere.
Add a "RefreshMainFrame(..)" call after the function
definition (by the way, that "item" argument isn't used
in your code?)

"StartupScript" is rendered at the end of the page,
so everything important should already exist before
any script tries to access it, but you still have to *call*
functions.
"ClientScript" is rendered at the start of the page,
so that functions defined in that block are available
when they are referenced later.

A note: the first parameter of RegisterStartupScript
doesn't specify "a function to be called", but is just
a server-side identification string. If you can generate
this script from multiple places (it's in a control, and you
might use multiple copies of that control), then you
can use this identification to find out if it's already generated.

Hans Kesting
 
You mean that i should write it like this :

js = "<script language=JavaScript>"

js &= "function RefreshMainFrame(){" & vbCrLf

js &= "window.open('homepage.aspx','mainFrame');" & vbCrLf

js &= "}" & vbcrlf

js &= "RefreshMainFrame()" & vbcrlf

js &= "</script>"
 

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

Back
Top