简体   繁体   中英

In .Net, is it possible to use Response.Write in a class that does not inherit from System.Web.UI.Page

Just been asked this question as a true / false in a telephone job interview and was a little stumped. Any ideas?

You can get hold of the Response object from the HttpContext static object:

System.Web.HttpContext.Current.Response.Write("Some Text")

If current returns null then the code is not being run as part of a page request. If you get asked the question again then that's the answer but a follow up question should be "why would you need to?"

The short answer is yes. In an interview id mention UserControl for an example.

Yes, of course. If you have reference do instance of "Respone", you can call any method on them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM