如何在类库中使用Response.Write()? [英] How to use Response.Write() in class library?

查看:220
本文介绍了如何在类库中使用Response.Write()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在类库中使用Response.Write()?



它给出了错误当前上下文中名称Response不存在 。



I am unable to use Response.Write() in class library?

It gives me error that "The name Response does not exist in the current context".

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Default_Construtor
{
    public class Class1
    {
        public void Show()
        {
            Response.Write("Hello World");
        }
    }
}





请建议。



谢谢&问候,

Aditya Kumar



Please suggest.

Thanks & Regards,
Aditya Kumar

推荐答案

如果可以避免,你不想在类库中这样做。但是,您可以使用完整命名来完成:



You don't want to do it in a class library, if you can avoid it. However, you can do it by using the full naming:

System.Web.HttpContext.Current.Response.Write(); // as i recall from memory.

这是一个不好的做法。

相反,你应该在类文件中设置一个标志,稍后在代码隐藏中使用它。



- KR
It's a bad practice.
Instead you should set one flag in class file and use it later in codebehind.

-KR


添加System.Web引用并在类文件中使用该命名空间。添加以下代码:

Add System.Web reference and use that namespace in your class file. Add below code:
namespace Default_Construtor
{
    public class Class1
    {
        public void Show()
        {
            System.Web.HttpContext.Current.Response.Write("Hello World");
        }
    }
}



从代码隐藏文件文件中调用Show()方法。


And call the Show() method from code-behind file file.


这篇关于如何在类库中使用Response.Write()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆