Calling javascript from a C# condition?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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.
 
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>");
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top