views:

225

answers:

3

Can anyone tell me how to show alert message inside the .cs file of class library project in c#?

I am calling a method of cs file in classlibrary project. Whenever the control comes to the alert message statement inside the method, alert message should be shown on the web page(aspx) and the next statement to the alert message statement should not be executed.

+4  A: 

Be careful about putting too much UI code in your class libraries. It sounds like your class library method should throw an exception. Then the calling code can trap the exception and display it to the user as needed.

David
+1  A: 

Your class library method should return the error to the caller, and it's up to the caller whether the error should be shown or not.

Mez
+1  A: 

In an application made of well-defined tiers, this should never be done.

There is a lack of detail in the question as to what you're trying to accomplish by doing this, but here are a few possibilities and solutions:

  • Using the alert as a substitute for debugging? Use the debugger and step through your code; inspect the variables as necessary.
  • Trying to capture the message of an exception that's getting thrown? Let the exception bubble up to the UI layer where you can catch it and show the message.
  • Trying to return a string from a database or from a localized lookup table? Return it as the result of a function or property, and show the value from the UI layer.
Jon Seigel