Click here to Skip to main content
15,565,801 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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".

C#
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");
        }
    }
}


Please suggest.

Thanks & Regards,
Aditya Kumar
Posted
Updated 6-Oct-15 8:32am
v2

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:

C#
System.Web.HttpContext.Current.Response.Write(); // as i recall from memory.
 
Share this answer
 
Comments
Aditakumar2311 7-Oct-15 0:40am    
Thanks RyanDev.
ZurdoDev 7-Oct-15 7:03am    
You're welcome.
It's a bad practice.
Instead you should set one flag in class file and use it later in codebehind.

-KR
 
Share this answer
 
Comments
Aditakumar2311 7-Oct-15 0:42am    
Thanks KrunalRohit
Krunal Rohit 7-Oct-15 0:47am    
Please remove that Ji :D

-KR
Aditakumar2311 7-Oct-15 15:29pm    
Hi,

Can you please tell me how set one flag in class file and use it later in code behind?
Krunal Rohit 8-Oct-15 3:31am    
Using bool. you can check for true/false in code behind.

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

And call the Show() method from code-behind file file.
 
Share this answer
 
Comments
Aditakumar2311 7-Oct-15 0:43am    
Thanks Manas_Kumar

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900