Context or URL ?

S

Steph

Hi,

Is it better to use the URL method to send informations to a page, or to use
the context method ?

Thanks.
 
W

WJ

If the caller is of "Page" class, then Response.Redirect("url.aspx",..)
would be more than enough. If the caller is not of class "Page", then you
have to use HttpContext.

John
 
K

Karl Seguin

I don't understand this question. You'd use the QueryString (what I think
you mean by "URL Method") and the HttpContext for very different
situations. Accross requests you can't use HttpContext, within a request
you can't use Querystring....

Perhaps this article would help:
http://openmymind.net/index.aspx?documentId=6

Karl
 
S

Steph

Ok, my question was not so clear...
I have page1 and page2
Is it better to use in page2:
A/ Request.Querystring
B/ page1 mypage = (page1)Context.handler
label1.text = page1.Name
(In page1 i have a Name property with a get (readonly)...)

Thanks.
 
K

Karl Seguin

Steph:

You can't have Page1 and Page2 loaded at the same time

where are these being used? where are you doing (page1)Context.handler
from? From a user control? Some class?

Karl
 
S

Steph

Ok, let's try something different...

I have a submit form on page1 and want to reach page2 and retreive the
values.
To do this, i have several methods (cache, shared variable, session
variable...) but i am focused on these:

* page1: on the button1 clic method for ex, i have
Response.Redirect["page2.aspx?id=45"] and on page2 i have label1.text =
Request.Querystring["id"]

* page1 : i create a property (id for ex...) with a get (do not need a set
of course...) and on the button1 clic method i have a
Server.Transfer("page2.aspx")
And on page2 i have:
page1 mypage = (page1)Context.handler
label1.text = page1.id

These two solutions both works. But i need to know if there is one better
than the other...

Is it more clear ?!

Thanks for taking time.
 
K

Karl Seguin

It's crystal clear :) Sorry, but without context it's difficult to
understand...

Each method has advantages and disadvantages:

Method 1 can be bookmarked, but it has ugly paths and puts an extra hit on
the client/server

Method 2 can't be bookmarked, but it's much prettier and more efficient

If you don't need to bookmark, I'd go with method 2.

I'd also improve it...instead of using Context.Handler, I'd store the values
in Context.Items and then retrieve them from Context.Items. Using
(page1)Context.Handler effectively binds Page2 to Page1 which should be
avoided if possible (which you can via Context.Items)

Karl
 
S

Steph

Ok, that's it !!
Thanks for answering.

But if you use Context.items, it's pretty like using Session variables no ?
And then, this may take a large amount of server memory, don't you think ?
 
K

Karl Seguin

Context.Item IS stored in memory, but only for the lifetime of a single
request...unlike session variables which are stored for the lifetime of a
user visit...as such they do share similarities, but I doubt you'll run into
any problems.

Karl
 

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,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top