开发者

How do I show a message box from inside a class in a class library?

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

I am calli开发者_StackOverflowng 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.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜