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
Peter Bucher [MVP] - 08 Dec 2007 17:27 GMT
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=mastertype+directive&meta=)
Me.Master.CheckResponseObject()
(Else)
CType(Me.Master, MyMasterPageType).CheckResponseObject()

Signature
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
Mark Rae [MVP] - 08 Dec 2007 20:06 GMT
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...

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Mark Fitzpatrick - 08 Dec 2007 22:06 GMT
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.

Signature
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression
> Hi,
>
[quoted text clipped - 58 lines]
>
> Mike
mike.gilmore@jccteam.com - 08 Dec 2007 22:46 GMT
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.
Mark Fitzpatrick - 09 Dec 2007 00:38 GMT
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.

Signature
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression
> Hi,
>
[quoted text clipped - 58 lines]
>
> Mike
mike.gilmore@jccteam.com - 09 Dec 2007 04:07 GMT
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...