PDA

Click to See Complete Forum and Search --> : Using Response & Request from a class?


starwiz
Jul 2nd, 2003, 11:53 AM
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:
Dim Refs as new Referrences
Refs.response = response
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?

Cander
Jul 2nd, 2003, 12:03 PM
you have to refer to the current httpcontext


System.Web.HttpContext.Current.Response.blah...

starwiz
Jul 2nd, 2003, 01:38 PM
I must be doing something else wrong:

In my class, I haveProtected myRequest As System.Web.HttpRequest
Protected myResponse As System.Web.HttpResponsedeclared.

In my new sub, I say:
myRequest = System.Web.HttpContext.Current.Request
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?