Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

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

like image 662
Gais Avatar asked May 07 '09 10:05

Gais


2 Answers

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?"

like image 112
Matthew Steeples Avatar answered Sep 18 '22 14:09

Matthew Steeples


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

like image 21
Mark Dickinson Avatar answered Sep 17 '22 14:09

Mark Dickinson