Results 1 to 3 of 3

Thread: Using Response & Request from a class?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2003
    Posts
    30

    Using Response & Request from a class?

    I'm trying to write a class that will encapsulate a bunch of response and request calls I'm doing. In the class, I deal with querystrings, read and write cookies, and will eventually be doing some SQL stuff...

    Right now, I'm having a problem with using response and request in the class.

    Originally, I wrote the class so that after it was created, I could change the request and response objects through properties. The code would look like this from calling the class:
    VB Code:
    1. Dim Refs as new Referrences
    2. Refs.response = response
    3. Refs.request = request
    Those two properties would set private data members inside the class equal to response and request.

    This didn't work.

    Any responses or requests I made would work until I left the page. So, for example, I could write and read cookies, so long as both the writing and reading were done on the same page.

    After this didn't work, I decided to try making my class inherit system.web.ui.usercontrol. In my new sub, I call mybase.new, so the object should be all created. When I run my program, however, and try to make references to the response or request objects which should be included with the system.web.ui.usercontrol object, I get the error "Object reference not set to an instance of an object." It doesn't matter if I try and reference request in the class by "request," "me.request," or "mybase.request"; the error is the same.

    I'm sure I'm doing something wrong...I've never written something like this before.

    The question, however, is: what?

    Can anyone help me?

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    you have to refer to the current httpcontext


    System.Web.HttpContext.Current.Response.blah...
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2003
    Posts
    30
    I must be doing something else wrong:

    In my class, I have
    VB Code:
    1. Protected myRequest As System.Web.HttpRequest
    2. Protected myResponse As System.Web.HttpResponse
    declared.

    In my new sub, I say:
    VB Code:
    1. myRequest = System.Web.HttpContext.Current.Request
    2. myResponse = System.Web.HttpContext.Current.Response
    , because I don't feel like referencing that long set of references every time I want to do a request or a response.

    I get the same effects as before by doing this.

    What's wrong?
    Last edited by starwiz; Jul 2nd, 2003 at 01:46 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width