accessing a registered startup script in c# code

Discussion in 'ASP .Net' started by Andy B, Jan 1, 2008.

  1. Andy B

    Andy B Guest

    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?
    Andy B, Jan 1, 2008
    #1
    1. Advertising

  2. "Andy B" <> wrote in message
    news:...

    >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
    Mark Rae [MVP], Jan 1, 2008
    #2
    1. Advertising

  3. Andy B

    marss Guest

    On 1 Січ, 21:49, "Andy B" <> 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
    marss, Jan 2, 2008
    #3
  4. "marss" <> wrote in message
    news:...

    > 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
    Mark Rae [MVP], Jan 2, 2008
    #4
  5. Andy B

    marss Guest

    On 2 Січ, 16:03, "Mark Rae [MVP]" <> wrote:
    > "marss" <> wrote in message
    >
    > news:...
    >
    > > 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
    marss, Jan 2, 2008
    #5
  6. "marss" <> wrote in message
    news:...

    > 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
    Mark Rae [MVP], Jan 2, 2008
    #6
  7. Andy B

    marss Guest

    On 2 Січ, 23:32, "Mark Rae [MVP]" <> 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
    marss, Jan 2, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harry Smith

    What is client startup script?

    Harry Smith, Nov 4, 2004, in forum: ASP .Net
    Replies:
    9
    Views:
    3,173
    Harry Smith
    Nov 5, 2004
  2. =?Utf-8?B?QWhtZWQ=?=

    remove a script registered with RegisterStartupScript

    =?Utf-8?B?QWhtZWQ=?=, Jun 13, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    8,788
  3. Steve Powell
    Replies:
    3
    Views:
    3,041
    Steve Powell
    Jun 21, 2005
  4. Velislav
    Replies:
    6
    Views:
    1,780
    Laurent Bugnion
    Nov 7, 2006
  5. Brad Tilley
    Replies:
    1
    Views:
    1,192
    Nobody
    Apr 3, 2011
Loading...

Share This Page