RegisterStartupScript not creating a <SCRIPT> block

G

Guest

When I do this in my page...
ClientScript.RegisterStartupScript(this.GetType(), "SomeScript",
"alert(\"Hi there\");");

it doesn't work AND when I view source, the alert() line is dumped into the
HTML but with no <SCRIPT> block around it. Why would this be happening?

Alex
 
T

Tony B

Alex Maghen said:
When I do this in my page...
ClientScript.RegisterStartupScript(this.GetType(), "SomeScript",
"alert(\"Hi there\");");

it doesn't work AND when I view source, the alert() line is dumped into
the
HTML but with no <SCRIPT> block around it. Why would this be happening?

It doesn't add the script blocks, it simply adds what ever you've specified
to the page just before the closing form tag for the page. You must include
the script tags around your client side script yourself.

ClientScript.RegisterStartupScript(this.GetType(), "SomeScript",
"<script>alert(\"Hi there\");</" + "script>");
 
G

Guest

Alex said:
When I do this in my page...
ClientScript.RegisterStartupScript(this.GetType(), "SomeScript",
"alert(\"Hi there\");");

it doesn't work AND when I view source, the alert() line is dumped into the
HTML but with no <SCRIPT> block around it. Why would this be happening?

Because you haven't specified that it should add script tags.

ClientScript.RegisterStartupScript(this.GetType(), "SomeScript",
"alert(\"Hi there\");", true);
 
T

Tony B

Göran Andersson said:
Because you haven't specified that it should add script tags.

ClientScript.RegisterStartupScript(this.GetType(), "SomeScript",
"alert(\"Hi there\");", true);

Cool, I didn't know that the new 2.0 version added tags for you. I should
pay more attention ;-) My earlier post refers to the old
Page.RegisterStartupScript which didn't add tags and I incorrectly assumed
that this was still the case.
 
G

Guest

VERY cool. And thanks!

Alex

Tony B said:
Cool, I didn't know that the new 2.0 version added tags for you. I should
pay more attention ;-) My earlier post refers to the old
Page.RegisterStartupScript which didn't add tags and I incorrectly assumed
that this was still the case.
 

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

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top