Friday, August 15, 2008

How to Use Response Object in a Class

If you try to use
Response.Write(MyString);
Method for example in a class you will receive an error telling you that the Response Object is not available in this context.

In order to use the Response Object in a class without having this error, instead of writing
Response.Write(MyString);
write this
HttpContext.Current.Response.Write(MyString);
Or you can use any method of the Response Object.

And don't forget to write Using System.Web in the top of the class.

4 comments:

  1. thank you this good article

    ReplyDelete
  2. Chokran akhi, i ve been searching for a lot of time before finding the solution on this page.
    Allah yjazik bikhir

    Abou Hafsa,
    Morocco

    ReplyDelete
  3. Though I am using System.Web but I am not able to use HttpContext.CurrentPage......

    ReplyDelete