Home All Groups Group Topic Archive Search About

RE: Response is not available in this context

Author
14 Apr 2009 9:02 PM
NitRaGs
You will have to use HTTPContext.Response property to do that.

Your class must be under APP_Code as I can guess, that is why response is
not available.

You don't need to inherit from System.Web.UI.Page. Hope that helps.


Show quoteHide quote
"Joe Stateson" wrote:

> I added a gridview print routine to my dotnet 2 app.  It works fine after
> googling why it didnt work for an hour or more.
> Since I got several grids on various pages I thought I would add it to my
> "constant class" which all my codebehinds have and I put all my common code
> in it.
>
> namespace Training
> {
> ...
>  public class ConstClass
>  {
>   ...
>     public void print(GridView gv, strFilename)
>   {
>      Response.Clear();
>      ..etc..
>    }
>   ...
>  }
> }
> the above would not compile until I added System.Web.UI.Page as in
>
> public class ConstClass : System.Web.UI.Page
>
>
> ok, it finally recognized "Response" and compiled. Unfortunately, it wont
> run and gives me the error message "Response is not available in this
> context"
>
> There is something wrong with how I defined my class I suspect.  All I
> wanted to do was to call the "print" function from any of my pages and not
> have to put the print function in each C# page.  I am doing something wrong,
> yet all my other functions get called and work ok (they do not have
> "response").
>
>
> I call the print function as outlined below
> =======
> protected void Page_Load(object sender, EventArgs e)
>         {
>             if (null == Session["cUsefulFunctions"])
>                 Session["cUsefulFunctions"] = new ConstClass(Session);
>             cUsefulFunctions = (ConstClass)Session["cUsefulFunctions"];
>   ..etc..
>
>  protected void btnPrint_Click(object sender, EventArgs e)
>         {
>             cUsefulFunctions.print(gv4needed, "needed.xls");
>         }
>
>
> Regards
> Joseph
>
>
>