By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,454 Members | 3,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,454 IT Pros & Developers. It's quick & easy.

Munging URLs to store data

P: n/a
Hello. I'm a reasonably new ASP.NET programmer
with no prior ASP or web development experience,
but a lot of general programming experience. I'm
using Visual Web Developer Beta Express 2005.

I'm trying to find a way to store data in the
URL of my pages. I know that SessionState does
this if you go cookieless, and that's useful but
it's not what I want because the real data is
stored on the server, and only an ID code is
stored in the URL.

What I'm doing is implementing a database search
that displays results in a manner similar to
Google, such that 32 results will be displayed on
four pages, with 10 results per page. Of course,
there's only one actual "search results" page and
the virtual page the user is on is stored in a
variable, Session("ResultsPage"). When the user
presses the LinkButton to take them to the next
page of results, what actually happens is that the
variable is incremented by one, the same page is
reposted and the Page_Load function fills an
HttpPlaceholder Control with the next set of
results.

Now, this all works excelently... until you take
into account the browser's back button. When the
user has gone from the Search page to Results Page 1,
then Results Page 2, pressing Back should take them
back to Results Page 1, but of course it doesn't,
since 1 and 2 are really the same page reposted
differently due to data in a cookie.

Since a browser's history is based on URLs, you
clearly want to store the ResultsPage variable in
the URL itself, so that Back works properly. If you
look at the URLs Google uses when you search, you
can see that it does exactly this.

So anyway, my question is how you achieve this
URL-mangling in ASP.NET. I've read through every
description of the HttpSessionState class that I
can find, and I can't find any referance to URL-
variables in a non-cookieless session.

If someone could tell me where in the Framework
this functionality could be found, I'd greatly
appreuciate it. I just need the procedure calls
and class names that are used; I can learn the
rest easily myself.

Thanks for your time and interest,

-- Julian Mensch

Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
It sounds like you're looking for the QueryString collection (accessible
through the Request object). The QueryString collection contains all of the
name/value pairs contained after the '?' in a given URI. For the URI:
http://www.somesite.com/SearchResults.aspx?pageNumber=1
pageNumber=1 is the QueryString.

I obviously don't know the specifics of your solution but one way to
implement using a querystring is to use a Hyperlink control and set the
NavigateUrl property to SearchResults.aspx?pageNumber=1 or
SearchResults.aspx?pageNumber=2, etc...

To retrieve the value from the QueryString, just use:
[C#]
int pageNumber = Int32.Parse(Request.QueryString["pageNumber"]);

[VB - sorry if this is syntactically incorrect, I usually use C#]
Dim pageNumber as integer =
Int32.Parse(Request.QueryString.Item("pageNumber") )

In either case, when reading the value, you should first make sure that it
exists in the collection (It's not null/nothing).

HTH
----------------
Dave Fancher
http://www.davefancher.com

<jm*****@shaw.ca> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hello. I'm a reasonably new ASP.NET programmer
with no prior ASP or web development experience,
but a lot of general programming experience. I'm
using Visual Web Developer Beta Express 2005.

I'm trying to find a way to store data in the
URL of my pages. I know that SessionState does
this if you go cookieless, and that's useful but
it's not what I want because the real data is
stored on the server, and only an ID code is
stored in the URL.

What I'm doing is implementing a database search
that displays results in a manner similar to
Google, such that 32 results will be displayed on
four pages, with 10 results per page. Of course,
there's only one actual "search results" page and
the virtual page the user is on is stored in a
variable, Session("ResultsPage"). When the user
presses the LinkButton to take them to the next
page of results, what actually happens is that the
variable is incremented by one, the same page is
reposted and the Page_Load function fills an
HttpPlaceholder Control with the next set of
results.

Now, this all works excelently... until you take
into account the browser's back button. When the
user has gone from the Search page to Results Page 1,
then Results Page 2, pressing Back should take them
back to Results Page 1, but of course it doesn't,
since 1 and 2 are really the same page reposted
differently due to data in a cookie.

Since a browser's history is based on URLs, you
clearly want to store the ResultsPage variable in
the URL itself, so that Back works properly. If you
look at the URLs Google uses when you search, you
can see that it does exactly this.

So anyway, my question is how you achieve this
URL-mangling in ASP.NET. I've read through every
description of the HttpSessionState class that I
can find, and I can't find any referance to URL-
variables in a non-cookieless session.

If someone could tell me where in the Framework
this functionality could be found, I'd greatly
appreuciate it. I just need the procedure calls
and class names that are used; I can learn the
rest easily myself.

Thanks for your time and interest,

-- Julian Mensch

Nov 19 '05 #2

P: n/a
Yes, this is exactly what I needed. The
Framework is very large, and sometimes it
just becomes difficult to find the right
calls.

Thank you graciously for your help.

-- Julian

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.