how do you execute javascript after script is regsistered?

S

simon

hello,
what code would i use to kick off a javascript script after i had
registered it?

If (Not Page.IsClientScriptBlockRegistered("jsScript")) Then
Page.RegisterClientScriptBlock("jsScript", strScript)
End If

looking to kick off a script from inside a codebehind, but
conditionally not on an onClick event.

is there a way to do this?
have also played around with
IsStartupScriptRegistered/RegisterStartupScript
but still not sure of how to call that script from one of my functions
in my codebehind

any help would be apprecaited! thanks
 
C

Cor Ligthert [MVP]

Simon,

Please do not start new threads if you did not got answers in the other one.

The sample is there,

Cor
 
S

simon

hello, sorry for the bad thread etiquette. thought that my question
would get passed over since there were replies. thanks for the link,
i'm going to check it out now...
 
B

Bruce Barker

you need to look at how asp.net works:

1) server build page html
2) server sends page html to browser
3) browser parses and loads html

your asp.net code runs in step 1
your javascript runs in step 3

with this model, obviously server code can not call client code. there are a
couple a ways to control when the browser runs the client script. the script
can be tied to the browser onload event, a click event, or inline (processed
during page parse). RegisterStartupScript, renders a script block just
before the closing form tag, so it a handly plce to inline script.

-- bruce (sqlwork.com)
 
S

simon

thanks bruce. i'm getting the clearer picture of client vs server
processing.
regarding inline, that is theoretically what i'm trying to do here
if a condition arrises in the parsing, call a javascript function;
maybe i need to make a little popup window instead of an alert and
call that. once they click Ok send them to the page i originally
intended.
maybe i'm missing the understanding of inline processing. would a vb
fucntion call (based on an event) be considered inline processing?
 
B

Bruce Barker

no.


<html>
<body>
<script>

// inline javascript - executed during page parse by browser

document.write("<input type=button onclick='btnClick()'>");

// javascript function executed by user event

function btnClick()
{
alert("clicked button");
}
</script>
</body>
</htm>


-- bruce (sqlwork.com)
 
S

simon

thanks for clarifying
no.


<html>
<body>
<script>

// inline javascript - executed during page parse by browser

document.write("<input type=button onclick='btnClick()'>");

// javascript function executed by user event

function btnClick()
{
alert("clicked button");
}
</script>
</body>
</htm>


-- bruce (sqlwork.com)
 

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

Top