RegisterStartupScript not creating a <SCRIPT> block

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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>");
 
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);
 
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.
 
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

Back
Top