Using Response/Request in Custom Controls

  • Thread starter Thread starter Jeremy Ames
  • Start date Start date
J

Jeremy Ames

I am trying to use the the response and request objects in my custom
control, but I keep getting an error that the objects have not been
referenced. I have put in a using statement for System.Web to gain access to
HttpRequest and HttpResponse, but that is really not helping. Can someone
please give me some insight here?
 
Jeremy,

The Request and the Response are not exposed by the Control class.
Rather, you can get them through the Page property, or you can get them
through the HttpContext instance returned by the static Current property on
the HttpContext class.

Hope this helps.
 
Can you give an example? I have tried using Page.Response and Page.Request
but I get another error.

message Jeremy,

The Request and the Response are not exposed by the Control class.
Rather, you can get them through the Page property, or you can get them
through the HttpContext instance returned by the static Current property on
the HttpContext class.

Hope this helps.
 
Jeremy,

Can you be more specific about the error you are getting?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jeremy Ames said:
Can you give an example? I have tried using Page.Response and Page.Request
but I get another error.

message Jeremy,

The Request and the Response are not exposed by the Control class.
Rather, you can get them through the Page property, or you can get them
through the HttpContext instance returned by the static Current property on
the HttpContext class.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jeremy Ames said:
I am trying to use the the response and request objects in my custom
control, but I keep getting an error that the objects have not been
referenced. I have put in a using statement for System.Web to gain
access
to
HttpRequest and HttpResponse, but that is really not helping. Can someone
please give me some insight here?
 
The error message I am getting when using
Page.Request.ServerVariables["Script_Name"] is "Object reference not set to
an instance of an object."

message Jeremy,

Can you be more specific about the error you are getting?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jeremy Ames said:
Can you give an example? I have tried using Page.Response and Page.Request
but I get another error.

message Jeremy,

The Request and the Response are not exposed by the Control class.
Rather, you can get them through the Page property, or you can get them
through the HttpContext instance returned by the static Current property on
the HttpContext class.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jeremy Ames said:
I am trying to use the the response and request objects in my custom
control, but I keep getting an error that the objects have not been
referenced. I have put in a using statement for System.Web to gain
access
to
HttpRequest and HttpResponse, but that is really not helping. Can someone
please give me some insight here?
 
Jeremy,

This means that "Script_Name" doesn't return a key. This is different
from the property not existing. Are you sure that the key points to a valid
value?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jeremy Ames said:
The error message I am getting when using
Page.Request.ServerVariables["Script_Name"] is "Object reference not set to
an instance of an object."

message Jeremy,

Can you be more specific about the error you are getting?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jeremy Ames said:
Can you give an example? I have tried using Page.Response and Page.Request
but I get another error.

message Jeremy,

The Request and the Response are not exposed by the Control class.
Rather, you can get them through the Page property, or you can get them
through the HttpContext instance returned by the static Current property on
the HttpContext class.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jeremy Ames said:
I am trying to use the the response and request objects in my custom
control, but I keep getting an error that the objects have not been
referenced. I have put in a using statement for System.Web to gain
access
to
HttpRequest and HttpResponse, but that is really not helping. Can someone
please give me some insight here?
 
Actually, that was supposed to say "Server_Name"

message Jeremy,

This means that "Script_Name" doesn't return a key. This is different
from the property not existing. Are you sure that the key points to a valid
value?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jeremy Ames said:
The error message I am getting when using
Page.Request.ServerVariables["Script_Name"] is "Object reference not set to
an instance of an object."

message Jeremy,

Can you be more specific about the error you are getting?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jeremy Ames said:
Can you give an example? I have tried using Page.Response and Page.Request
but I get another error.

message Jeremy,

The Request and the Response are not exposed by the Control class.
Rather, you can get them through the Page property, or you can get them
through the HttpContext instance returned by the static Current property on
the HttpContext class.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jeremy Ames said:
I am trying to use the the response and request objects in my custom
control, but I keep getting an error that the objects have not been
referenced. I have put in a using statement for System.Web to gain
access
to
HttpRequest and HttpResponse, but that is really not helping. Can someone
please give me some insight here?
 
Back
Top