Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Response Object not working in Master Page

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mike.gilmore@jccteam.com - 08 Dec 2007 16:55 GMT
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...

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.