|
-
Jul 2nd, 2003, 11:53 AM
#1
Thread Starter
Junior Member
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:
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?
-
Jul 2nd, 2003, 12:03 PM
#2
you have to refer to the current httpcontext
System.Web.HttpContext.Current.Response.blah...
-
Jul 2nd, 2003, 01:38 PM
#3
Thread Starter
Junior Member
I must be doing something else wrong:
In my class, I have
VB Code:
Protected myRequest As System.Web.HttpRequest
Protected myResponse As System.Web.HttpResponse
declared.
In my new sub, I say:
VB Code:
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?
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|