PC Review


Reply
Thread Tools Rate Thread

Calling javascript from a C# condition?

 
 
=?Utf-8?B?Vk1J?=
Guest
Posts: n/a
 
      23rd Jun 2006
How can I call my javascript from within my C# "IF" statement?
I have a function called dirError() that only displays an alert:

function dirError()
{
alert('Bad directory');
}

From my C# code, I want to do this:
if (fileEntries.Length <= 0)
{
//CALL javaScript function dirError
}

Any help is appreciated.

Thanks.
 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      23rd Jun 2006
VMI,

This is assuming you are running in ASP.NET. You can't call the
javascript function. Rather, you need to inject the javascript code into
the page returned.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"VMI" <(E-Mail Removed)> wrote in message
news:06AD391D-CA0A-4C12-B0AE-(E-Mail Removed)...
> How can I call my javascript from within my C# "IF" statement?
> I have a function called dirError() that only displays an alert:
>
> function dirError()
> {
> alert('Bad directory');
> }
>
> From my C# code, I want to do this:
> if (fileEntries.Length <= 0)
> {
> //CALL javaScript function dirError
> }
>
> Any help is appreciated.
>
> Thanks.



 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      23rd Jun 2006
VMI,
since your Javascript function is client-side code, the only way you can
make a call to it from server-side code is to inject the call as client
script into the page. Here is an example:

if (fileEntries.Length <= 0)
{
Response.Write("<script>dirError();</script>");
}



--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




"VMI" wrote:

> How can I call my javascript from within my C# "IF" statement?
> I have a function called dirError() that only displays an alert:
>
> function dirError()
> {
> alert('Bad directory');
> }
>
> From my C# code, I want to do this:
> if (fileEntries.Length <= 0)
> {
> //CALL javaScript function dirError
> }
>
> Any help is appreciated.
>
> Thanks.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Calling Javascript srini.venkatesan@gmail.com Microsoft ASP .NET 5 6th Oct 2006 05:27 AM
Race Condition with Javascript - Any ideas? chris johnson Windows XP Internet Explorer 0 12th Jul 2006 07:19 PM
Calling WS from Javascript Ganesh Ramamurthy Microsoft ASP .NET 5 13th Dec 2004 05:41 AM
How To Create a JavaScript Confirm inside a Condition in ASP.NET Joe Finsterwald Microsoft ASP .NET 0 5th Dec 2003 06:32 PM
Calling JavaScript from C# Jakub Gutkowski Microsoft C# .NET 3 16th Nov 2003 10:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:18 PM.