Is there a way I can avoid bringing in the Page object?

A

AAaron123

In App_Code I'd like to develop a library of common usage procedures. The
following works but notice I had to bring in a Page object or both Session
and Response would be undeclared.

I believe this causes late binding. Correct?

Is there a way I can avoid bringing in the Page object?

Thanks



Imports Microsoft.VisualBasic

Public Class Utility

Public Shared Sub SaveCookie(ByVal P As Page, ByVal CookieName As String,
ByVal CookieValue As String)

Dim styleCookie As HttpCookie = New HttpCookie(CookieName)

styleCookie.Value = CookieValue

styleCookie.Expires = DateTime.Now.AddYears(1)

P.Response.Cookies.Add(styleCookie)

P.Session(CookieName) = styleCookie.Value

End Sub

End Class
 
A

AAaron123

THAT FIXED IT.

Not sure about what I read. The browser makes a request and HttpContext
includes all the data in the request. Is that correct?

One time in the debugger I tried to see what was in the 2 Items but it
showed Nothing" for both. Are the Items of interest?

Also, if HttpContext is the data in the browser request what is in the
Response property?

The doc's typically give a one-line description of the properties which is
not enough for me.


Thanks for the help
 
A

AAaron123

The collection of objects used to create the final markup which will be
streamed to the client browser.
I can't figure how much it contains at a given time. If I'm in a code behind
event that later will set some markup into a Literal control it obvisoly
can't contain that markup yet. If I already wrote to it I guess it'll
contain that. But what else. The contents of the .aspx file is subject to
change by the code behind - so I'm confused about what Response does
contain.

There is lots of good tutorial stuff on the Internet butb sometimes the big
picture is hard to discern.

Thanks a lot
 
A

AAaron123

I got the following reply from George via e-mail instead of the NG because
he clicked the wrong button. I implemented his "c" suggestion. Works well so
I and thought I'd pass it on.

a. It does not cause late binding.

b. You can avoid using page but then you need to pass Response and Session
to SaveCookie.

c. The best way is to base you Utility from Page class and then your pages
from
Utility (instead of Page).

On this case all you pages will have SaveCookie method from parent class and
you do not need to pass Page object since it will have access to Response
and Session since it's based of Page class.


George.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top