Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to run a javascrpt function from the server?

Reply
Thread Tools

How to run a javascrpt function from the server?

 
 
Rob Meade
Guest
Posts: n/a
 
      03-16-2007
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


 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      03-16-2007
"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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?S3lsZUs=?=
Guest
Posts: n/a
 
      03-16-2007
Rob

I usually do something like this:

string message = "whatever you want it to be";
Page.RegisterClientScriptBlock("messagebox","<scri pt 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
>
>
>

 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      03-16-2007
"KyleK" <> wrote in message
news:7A1B3B92-B72C-4888-93A4-...

> I usually do something like this:
>
> string message = "whatever you want it to be";
> Page.RegisterClientScriptBlock("messagebox","<scri pt 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);


 
Reply With Quote
 
Rob Meade
Guest
Posts: n/a
 
      03-16-2007
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


 
Reply With Quote
 
=?Utf-8?B?S3lsZUs=?=
Guest
Posts: n/a
 
      03-16-2007
Oops thanks Mark I forgot that Page.RegisterClientScriptBlock was deprecated.
--
Kyle Kelin
..NET Developer


"Mark Rae" wrote:

> "KyleK" <> wrote in message
> news:7A1B3B92-B72C-4888-93A4-...
>
> > I usually do something like this:
> >
> > string message = "whatever you want it to be";
> > Page.RegisterClientScriptBlock("messagebox","<scri pt 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);
>
>
>

 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      03-16-2007
"KyleK" <> wrote in message
news:8DAA7F6A-C6CE-4594-B0A2-...

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


And also <script language=javascript>, but we've done that one to death
recently...


 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      03-18-2007
This may help you:

http://usableasp.net/DeveloperPage.a...rAndClient.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
>



 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
insert javascrpt into textarea? globalrev Javascript 15 05-12-2008 12:03 PM
Javascrpt and User Controls. Help! =?Utf-8?B?ZXJpYw==?= ASP .Net 6 11-09-2007 02:04 PM
javascrpt IDE Grzegorz ¦lusarek Javascript 3 05-20-2006 02:29 PM
Where is "official", not Microsoft, spec for javascrpt, etc.? Howard Kaikow Javascript 4 10-12-2004 10:47 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57