Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System.Web.UI.Page passed into a class function

Status
Not open for further replies.

humour

Programmer
Nov 24, 2003
87
What I want to do is have a general class function that I can instantiate on any of my intranet pages and have it check for a cookie (which stores my employee id). No cookie found the code will redirect to a page and ask you for it (pretty simple). I do it in ASP but the function is part of an include.

How I want to do it in vb.net is to pass (ME) which is inherited from System.Web.UI.Page and pass it byRef into the function so I can invoke the cookie request function.

My code is below - the error I get is:

Object reference not set to an instance of an object.


Public Function LoadPage()
Dim sRC As String
' Me is the webform page (inherited from
' System.Web.UI.Page of course
sRC = pc.GetEmployeeIdCookie(Me)


Class ParamClass
Function GetEmployeeIdCookie(ByRef vWebPage As System.Web.UI.Page) As String
Dim EmpID As String
'EmpID = vWebPage.Request.Cookies("a")
EmpID = vWebPage.Request.Cookies("jjemployeeid").ToString
If Len(EmpID) < 1 Then
EmpID = ""
vWebPage.Response.Redirect("test.asp")
End If
Return EmpID
End Function
 
I may not be understaning the problem correctly but it appears to me that the code above does not create an instance of the class paramclass .

You use the variable pc.getemployeeid to access the class method getemployeeidcookie but where is the variable pc instantiated?

Not sure if this will help -apogies if I have got the wrong end of the stick.

HTH
 

Dear Newora....


I found the problem.

The error: "Object reference not set to an instance of an object. "

Was occuring here:
"vWebPage.Request.Cookies("jjemployeeid").ToString

Why: Because I was looking for a cookie that was created using ASP application not a asp.net application. It turns out that cookies between asp and asp.net are not univerally co-compatable. I have since googled workarounds but I havent got them to work yet. I am sure that something will (its not hugely important to my app right at the moment).

AS to your reply... I hadnt shown a code fragment where I WAS instantiating a PARAMClass... I had a line not shown in the post similar to :

Dim PCas New IntranetParamClass

Thanks for your reply.


 
Good, I'am glad that you have found the problem.

I thought that I might have been on the wrong track with my answer - apologies for that.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top