By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,458 Members | 1,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,458 IT Pros & Developers. It's quick & easy.

Response Object not working in Master Page

P: n/a
Hi,

I'm trying to move all my custom validation code into the master
page. Unfortunately anytime I use the response, request, or trace
objects in any master page module (other than page_load), " Object
reference not set to an instance of an object." is the error I
receive.

Below is a sample of code that will not work on my web server. Any
suggestions/advice are appreciated.

Thanks.

Debug.aspx.vb (btnGo - is a web control object in Default.aspx)

Partial Class Debug
Inherits System.Web.UI.Page

Protected Sub btnGo_Command(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.CommandEventArgs) Handles btnGo.Command

Dim objMaster As New DebugMaster
With objMaster

.CheckResponseObject()

End With

End Sub
End Class

DebugMaster.Master.Vb

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Response.Write("Inside the Master Page - Page_Load event
handler")

End Sub

Public Sub CheckResponseObject()

Response.Write("Inside the Master Page - CheckResponseObject
method")

End Sub
----------------------

On load the Master Page's page load "Response.Write" works, however
when the btnGo event is called (thus calling CheckResponseObject), the
page returns an " Object reference not set to an instance of an
object." exception.

Similar errors are called when I use the request or trace objects as
well.

Any advice on how to resolve would be greatly appreciated.

Thanks,

Mike
Dec 8 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi Mike

You should generally be aware from using Response.Write() and Request.Form()
in a ASP.NET Project and in consequence not using it.
However, i think that would do your job:

(With the MasterType Directive, see:
http://www.google.ch/search?hl=de&q=...irective&meta=)
Me.Master.CheckResponseObject()

(Else)
CType(Me.Master, MyMasterPageType).CheckResponseObject()

--
Gruss, Peter Bucher
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET

Dec 8 '07 #2

P: n/a
<mi**********@jccteam.comwrote in message
news:e5**********************************@s19g2000 prg.googlegroups.com...

In addition to Peter's response, I'm slightly curious as to what you're
trying to achieve here...

There's no need to use Response.Write in ASP.NET - just put a breakpoint
where you would like your code to break, and hit the button...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Dec 8 '07 #3

P: n/a
To help the debug process, enable tracing for your application and use
Trace.Write() to output messages to the trace log for testing. It's much
more powerful than the old Response.Write method of dumping variables and
hints at different points in the page.
--
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression

<mi**********@jccteam.comwrote in message
news:e5**********************************@s19g2000 prg.googlegroups.com...
Hi,

I'm trying to move all my custom validation code into the master
page. Unfortunately anytime I use the response, request, or trace
objects in any master page module (other than page_load), " Object
reference not set to an instance of an object." is the error I
receive.

Below is a sample of code that will not work on my web server. Any
suggestions/advice are appreciated.

Thanks.

Debug.aspx.vb (btnGo - is a web control object in Default.aspx)

Partial Class Debug
Inherits System.Web.UI.Page

Protected Sub btnGo_Command(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.CommandEventArgs) Handles btnGo.Command

Dim objMaster As New DebugMaster
With objMaster

.CheckResponseObject()

End With

End Sub
End Class

DebugMaster.Master.Vb

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Response.Write("Inside the Master Page - Page_Load event
handler")

End Sub

Public Sub CheckResponseObject()

Response.Write("Inside the Master Page - CheckResponseObject
method")

End Sub
----------------------

On load the Master Page's page load "Response.Write" works, however
when the btnGo event is called (thus calling CheckResponseObject), the
page returns an " Object reference not set to an instance of an
object." exception.

Similar errors are called when I use the request or trace objects as
well.

Any advice on how to resolve would be greatly appreciated.

Thanks,

Mike
Dec 8 '07 #4

P: n/a
Thanks to all for responding to my post and on a Saturday! In an
effort to make my example simple, I rewrote it using only one
response.write statement. In reality, I'm actually trying to call
Request.Browser.Cookies (as part of my validation routine). I'm not,
nor do I in practice, using response.write in my code ;-).

Neither the response, request, or trace objects work. All return the
"Object reference not set to an instance of an object." exception.

I will read the link provided.

Again, thank you.
Dec 8 '07 #5

P: n/a
The Response object is actually a shortcut. When you have a normal page, the
System.Web.UI.Page class basically let's you use Response, Request, etc.
because it's actually giving you a shortcut to the real class. Anywhere
outside of a page (and this includes a MasterPage because it inherits from a
different base clase) you need to use HttpContext.Current.Response or
HttpContext.Current.Request. Then you can get at the objects and properties
you want. The same goes for things like the Session and Server objects as
well.
--
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression

<mi**********@jccteam.comwrote in message
news:e5**********************************@s19g2000 prg.googlegroups.com...
Hi,

I'm trying to move all my custom validation code into the master
page. Unfortunately anytime I use the response, request, or trace
objects in any master page module (other than page_load), " Object
reference not set to an instance of an object." is the error I
receive.

Below is a sample of code that will not work on my web server. Any
suggestions/advice are appreciated.

Thanks.

Debug.aspx.vb (btnGo - is a web control object in Default.aspx)

Partial Class Debug
Inherits System.Web.UI.Page

Protected Sub btnGo_Command(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.CommandEventArgs) Handles btnGo.Command

Dim objMaster As New DebugMaster
With objMaster

.CheckResponseObject()

End With

End Sub
End Class

DebugMaster.Master.Vb

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Response.Write("Inside the Master Page - Page_Load event
handler")

End Sub

Public Sub CheckResponseObject()

Response.Write("Inside the Master Page - CheckResponseObject
method")

End Sub
----------------------

On load the Master Page's page load "Response.Write" works, however
when the btnGo event is called (thus calling CheckResponseObject), the
page returns an " Object reference not set to an instance of an
object." exception.

Similar errors are called when I use the request or trace objects as
well.

Any advice on how to resolve would be greatly appreciated.

Thanks,

Mike
Dec 9 '07 #6

P: n/a
Mark,

Thanks for the reply. I implemented your logic using the full name
and it worked!

The one thing I don't understand (and probably never will) is why the
"shortcut" response/request worked in the master page's page_load.

Again thanks, you saved many a headache...

Dec 9 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.