How to run a javascrpt function from the server?

Discussion in 'ASP .Net' started by Rob Meade, Mar 16, 2007.

  1. Rob Meade

    Rob Meade Guest

    Hi all,

    I need to be able to run a javascript function on my page (to launch a popup
    window) from my .net code which is run after a trigger in an update panel is
    launched (Ajax etc)...

    Can anyone give me some pointers...

    Thanks in advance,

    Regards

    Rob
     
    Rob Meade, Mar 16, 2007
    #1
    1. Advertising

  2. "Rob Meade" <> wrote in message
    news:ekFqWM%...
    > Hi all,
    >
    > I need to be able to run a javascript function on my page (to launch a
    > popup window) from my .net code which is run after a trigger in an update
    > panel is launched (Ajax etc)...
    >
    > Can anyone give me some pointers...


    The server can't run client code.

    Please be more explicit about what you're trying to accomplish, and maybe
    we'll have some thoughts.

    John
     
    John Saunders, Mar 16, 2007
    #2
    1. Advertising

  3. Rob

    I usually do something like this:

    string message = "whatever you want it to be";
    Page.RegisterClientScriptBlock("messagebox","<script language=javascript>
    alert('" + message.Replace("'", "\'").Replace("\n", " ") + "');</script>\n");

    Put this code in the code behind event you want to fire.


    Let me know if this helps.

    --
    Kyle Kelin
    ..NET Developer


    "Rob Meade" wrote:

    > I should have stated, I'm using .Net 2.0 via Visual Studio 2005...(if that
    > makes any difference to any ideas people have etc)
    >
    > Rob
    >
    >
    >
     
    =?Utf-8?B?S3lsZUs=?=, Mar 16, 2007
    #3
  4. Rob Meade

    Mark Rae Guest

    "KyleK" <> wrote in message
    news:...

    > I usually do something like this:
    >
    > string message = "whatever you want it to be";
    > Page.RegisterClientScriptBlock("messagebox","<script language=javascript>
    > alert('" + message.Replace("'", "\'").Replace("\n", " ") +
    > "');</script>\n");


    Or, in v2...

    string message = "whatever you want it to be";
    ClientScript.RegisterClientScriptBlock("messagebox","alert('" +
    message.Replace("'", "\'").Replace("\n", " ") + "');", true);
     
    Mark Rae, Mar 16, 2007
    #4
  5. Rob Meade

    Rob Meade Guest

    Thanks for the replies chaps..

    Just to check then...

    So, if I do that in my code behind, does that actually "launch" the
    javascript or just write it to the page ready to be launched if you know
    what I mean?

    I have found for example that on my linkButton I can specific
    "OnClientClick" values, which I've entered for now as a javascript string
    which launches a window - alas, I am also setting a session variable on the
    onclick (code behind) and the popup is happening just a bit quicker than the
    session being set, so the first time its not set, but then if you hit
    refresh on the popup its fine...

    What I really want I guess is...

    code behind - set session, trigger popup to launch...

    Will your example(s) do that?

    Regards

    Rob
     
    Rob Meade, Mar 16, 2007
    #5
  6. Oops thanks Mark I forgot that Page.RegisterClientScriptBlock was deprecated.
    --
    Kyle Kelin
    ..NET Developer


    "Mark Rae" wrote:

    > "KyleK" <> wrote in message
    > news:...
    >
    > > I usually do something like this:
    > >
    > > string message = "whatever you want it to be";
    > > Page.RegisterClientScriptBlock("messagebox","<script language=javascript>
    > > alert('" + message.Replace("'", "\'").Replace("\n", " ") +
    > > "');</script>\n");

    >
    > Or, in v2...
    >
    > string message = "whatever you want it to be";
    > ClientScript.RegisterClientScriptBlock("messagebox","alert('" +
    > message.Replace("'", "\'").Replace("\n", " ") + "');", true);
    >
    >
    >
     
    =?Utf-8?B?S3lsZUs=?=, Mar 16, 2007
    #6
  7. Rob Meade

    Mark Rae Guest

    "KyleK" <> wrote in message
    news:...

    > Oops thanks Mark I forgot that Page.RegisterClientScriptBlock was
    > deprecated.


    And also <script language=javascript>, but we've done that one to death
    recently... ;-)
     
    Mark Rae, Mar 16, 2007
    #7
  8. This may help you:

    http://usableasp.net/DeveloperPage....o/HowToPassMessagesBetweenServerAndClient.htm

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Rob Meade" <> wrote in message
    news:ekFqWM%...
    > Hi all,
    >
    > I need to be able to run a javascript function on my page (to launch a
    > popup window) from my .net code which is run after a trigger in an update
    > panel is launched (Ajax etc)...
    >
    > Can anyone give me some pointers...
    >
    > Thanks in advance,
    >
    > Regards
    >
    > Rob
    >
     
    Eliyahu Goldin, Mar 18, 2007
    #8
    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. Replies:
    3
    Views:
    355
    Gabriel Genellina
    Jun 23, 2007
  2. =?Utf-8?B?ZXJpYw==?=

    Javascrpt and User Controls. Help!

    =?Utf-8?B?ZXJpYw==?=, Nov 8, 2007, in forum: ASP .Net
    Replies:
    6
    Views:
    382
    Kevin Spencer
    Nov 9, 2007
  3. Howard Kaikow
    Replies:
    4
    Views:
    87
    Stewart Gordon
    Oct 12, 2004
  4. Grzegorz ¦lusarek

    javascrpt IDE

    Grzegorz ¦lusarek, May 11, 2006, in forum: Javascript
    Replies:
    3
    Views:
    101
    Thomas 'PointedEars' Lahn
    May 20, 2006
  5. globalrev

    insert javascrpt into textarea?

    globalrev, May 11, 2008, in forum: Javascript
    Replies:
    15
    Views:
    225
    Dr J R Stockton
    May 12, 2008
Loading...

Share This Page