tags:

views:

89

answers:

4

I have an ASP.NET (C#) class that is used both on the client and server.

Depending on whether the code is being executed on the client or the server, it needs to behave differently.

What is the simplest & most efficient way of telling if the code is executing on the client or the server?

Thanks!

+3  A: 

unless you are running Silverlight 2 or Silverlight 3 There is no way for Asp.Net to run C# code in the client (the users' browser)

AndreasKnudsen
There is: a .NET WinForms user control ;)
Mehrdad Afshari
Doh! Dumb newbie question! You get answer credit by virtue of being the first out of the starting blocks! :)
Shaul
+2  A: 

It's executing on the server. Unless you are using Silverlight, C# is probably not run on the client.

Mehrdad Afshari
Do you mean "ASP.NET is probably not run on the client"?
Alex Angas
No, I used the word probably since there are other ways except Silverlight: a WinForms user control, an XBAP application, among others
Mehrdad Afshari
+2  A: 

Unless we're talking Silverlight here, there's not much choice: C# code is always executed on the server, JavaScript is executed on the client.

Anton Gogolev
+2  A: 

By your tags I see your talking about a web application not a client-server winforms app.

If it is in javascript, html and css, or silverlight it's happening in the browser. If it is happening in C#, it's happening on the server.

MatthewMartin