在.Net中,是否可以在不从System.Web.UI.Page继承的类中使用Response.Write

时间:2022-01-27 20:11:15

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

刚刚在电话工作面试中被问到这个问题的真假,并且有点难过。有任何想法吗?

3 个解决方案

#1


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

您可以从HttpContext静态对象获取Response对象:

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

如果current返回null,则代码不会作为页面请求的一部分运行。如果你再次被问到问题那么这就是答案,但后续问题应该是“为什么你需要?”

#2


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

简短的回答是肯定的。在一次采访中,id提到了UserControl的一个例子。

#3


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

当然是。如果您参考了“Respone”的实例,则可以调用它们上的任何方法。

#1


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

您可以从HttpContext静态对象获取Response对象:

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

如果current返回null,则代码不会作为页面请求的一部分运行。如果你再次被问到问题那么这就是答案,但后续问题应该是“为什么你需要?”

#2


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

简短的回答是肯定的。在一次采访中,id提到了UserControl的一个例子。

#3


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

当然是。如果您参考了“Respone”的实例,则可以调用它们上的任何方法。