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