473,320 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Calling javascript from a C# condition?

VMI
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.
Jun 23 '06 #1
2 2011
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]
- mv*@spam.guard.caspershouse.com

"VMI" <VM*@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...
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.

Jun 23 '06 #2
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.

Jun 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Simula | last post by:
I am developing an HTML javascript application and I want to preserve state in a way that can be book-marked. I chose HTML anchors as a means of preserving state. When the application changes...
16
by: Brian Henry | last post by:
Is there a way to launch a javascript command from within VB code? For instance, to issue a window.open(some url) if a certain condition is met. I know you can add the javacript to a control...
0
by: Caesar Augustus | last post by:
I'm having a problem with two different javascript controls in my app. The first chuck of javascript that I pasted into my app is the client-side calendar control popup which works fine when first...
2
by: Harold | last post by:
I have page A with form field and a button and when button is clicked it opens page B in another window. Page B has a treeview control and that is all. When something is selected I want the page...
5
by: Sekhar | last post by:
Hi all I have an ASP.NET Button Control. I woud like this button to make a Call to JavaScript function on some condition. How would i do this Thanks Sekhar
11
by: John Pote | last post by:
Hi everyone, I've just started adding JavaScript to some of my web pages. It then occurred to me that of course not everyone may have JavaScript in their browser and more probably may have...
2
by: nams | last post by:
Hi Frnds, Say I have vb code like this: Public Sub ll() MsgBox("heLOOOOOOOOOOOOOOOOOOOOOOOOOOOOO", MsgBoxStyle.OkOnly) End Sub The following script runs as soon as the page loads, no...
19
by: David Given | last post by:
I have a situation where I need to use GOTO in a Javascript program. No, I can't use break or continue. Yes, I really do know what I'm doing. What I've got is a huge mass of automatically...
3
by: q-rious | last post by:
Hello All, 1. I would like to pass some variables (x and y below) from Javascript to PHP, process them in PHP, and return some other variables (a abd b) back to Javascript. --(x,y)--...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.