accessing a registered startup script in c# code

  • Thread starter Thread starter Andy B
  • Start date Start date
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?
 
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...
 
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
 
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);
 
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
 
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);
 
ClientScript.RegisterStartupScript(GetType(), "AddNews", "alert('Sorry! For
some reason, the news article couldn\\'t be added. Try again later...');",
true);

Well, it is a variant. Quite good variant :)

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

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