Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > accessing a registered startup script in c# code

Reply
Thread Tools

accessing a registered startup script in c# code

 
 
Andy B
Guest
Posts: n/a
 
      01-01-2008
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?



 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      01-01-2008
"Andy B" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

>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...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
 
 
 
marss
Guest
Posts: n/a
 
      01-02-2008
On 1 Січ, 21:49, "Andy B" <(E-Mail Removed)> wrote:
> 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




 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      01-02-2008
"marss" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> 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);


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
marss
Guest
Posts: n/a
 
      01-02-2008
On 2 Січ, 16:03, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
> "marss" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
> > 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);
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net


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
 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      01-02-2008
"marss" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> 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);


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
marss
Guest
Posts: n/a
 
      01-02-2008
On 2 Січ, 23:32, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:

> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
registered trademark symbol in C++ source code Brad Tilley C++ 1 04-03-2011 03:24 PM
changing a registered client script block Velislav ASP .Net 6 11-07-2006 01:31 PM
remove a script registered with RegisterStartupScript =?Utf-8?B?QWhtZWQ=?= ASP .Net 6 07-18-2006 06:50 PM
remove script registered using RegisterClientScriptBlock Steve Powell ASP .Net 3 06-21-2005 08:41 AM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments