accessing a registered startup script in c# code

A

Andy B

I have this code in one of my methods:
ClientScript.RegisterStartupScript(GetType(), "AddNews",

"alert('Sorry! For some reason, the news article couldn't be added. Try
again later...');", true);


After it is registered, I will now need to make this script run. How do you
do that?
 
M

Mark Rae [MVP]

I have this code in one of my methods:
ClientScript.RegisterStartupScript(GetType(), "AddNews",

"alert('Sorry! For some reason, the news article couldn't be added. Try
again later...');", true);


After it is registered, I will now need to make this script run. How do
you do that?


??? It will run when your page loads...
 
M

marss

I have this code in one of my methods:
ClientScript.RegisterStartupScript(GetType(), "AddNews",

"alert('Sorry! For some reason, the news article couldn't be added. Try
again later...');", true);


Hi Andy

It does not execute while page is loading because of mistake in your
script. You can use single quotes to define a string in javascript
only if that string does not contain single quote itself.

Try this:
ClientScript.RegisterStartupScript(GetType(), "AddNews",
"alert(\"Sorry! For some reason, the news article couldn't be added.
Try again later...\");", true);

Regards,
Mykola
http://marss.co.ua
 
M

Mark Rae [MVP]

You can use single quotes to define a string in javascript
only if that string does not contain single quote itself.

That's not true - all you need to do is escape the single quote within the
string, e.g.

ClientScript.RegisterStartupScript(GetType(), "AddNews", "alert('Sorry! For
some reason, the news article couldn\'t be added. Try again later...');",
true);
 
M

marss

That's not true - all you need to do is escape the single quote within the
string, e.g.

ClientScript.RegisterStartupScript(GetType(), "AddNews", "alert('Sorry! For
some reason, the news article couldn\'t be added. Try again later...');",
true);

Hi Mark,

It is true, at least in that case. Try to test the example you
suggested and you'll see the problem.

Regards,
Mykola
http://marss.co.ua
 
M

Mark Rae [MVP]

It is true, at least in that case. Try to test the example you
suggested and you'll see the problem.

Apologies for the typo...

ClientScript.RegisterStartupScript(GetType(), "AddNews", "alert('Sorry! For
some reason, the news article couldn\\'t be added. Try again later...');",
true);
 

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,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top