473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

adding an item to a QueryString

PJ6
I thought this was going to be simple. I want to take an HttpRequest and add
an item to the QueryString.

First I tried to add it directly, but I got a "Collection is read-only."
error. So I decided to construct my own, new HttpRequest based on the
contents of the old one (from within a class that inherits from Page):

Dim q As New
System.Collections.Specialized.NameValueCollection (Me.Request.QueryString)
q.Add("TEST", test)
Dim r As New HttpRequest(Me.Request.FilePath, Me.Request.Url.ToString,
q.ToString)

Only this doesn't work, q.ToString returns
"System.Collections.Specialized.NameValueCollectio n". Do I really have to
serialize the QueryString myself? Is there really no built-in method to do
this?

I'm sure I misinterpreted what the constructor wants for FileName, but the
documentation offers no comment. Why is there no corresponding property?

Paul
Nov 19 '05 #1
7 1346
Try perhaps Response.Redirect if you want to direct the browser to a new
page and/or with a new querystring...
Else explain us what you want to do...

(you can't change the current request, it is what it is and you just handle
this).

--

"PJ6" <no****@nowhere.net> a écrit dans le message de
news:ui**************@TK2MSFTNGP09.phx.gbl...
I thought this was going to be simple. I want to take an HttpRequest and add an item to the QueryString.

First I tried to add it directly, but I got a "Collection is read-only."
error. So I decided to construct my own, new HttpRequest based on the
contents of the old one (from within a class that inherits from Page):

Dim q As New
System.Collections.Specialized.NameValueCollection (Me.Request.QueryString)
q.Add("TEST", test)
Dim r As New HttpRequest(Me.Request.FilePath, Me.Request.Url.ToString,
q.ToString)

Only this doesn't work, q.ToString returns
"System.Collections.Specialized.NameValueCollectio n". Do I really have to
serialize the QueryString myself? Is there really no built-in method to do
this?

I'm sure I misinterpreted what the constructor wants for FileName, but the
documentation offers no comment. Why is there no corresponding property?

Paul

Nov 19 '05 #2
PJ6
> Try perhaps Response.Redirect if you want to direct the browser to a new
page and/or with a new querystring...


And - to repeat my qestion - can one build this new query string using the
built-in object model, or does the logic for this have to be coded by hand?

Paul
Nov 19 '05 #3
PJ6 wrote:
I thought this was going to be simple. I want to take an HttpRequest
and add an item to the QueryString.

First I tried to add it directly, but I got a "Collection is
read-only." error. So I decided to construct my own, new HttpRequest
based on the contents of the old one (from within a class that
inherits from Page):

Dim q As New
System.Collections.Specialized.NameValueCollection (Me.Request.QueryStr
ing) q.Add("TEST", test) Dim r As New
HttpRequest(Me.Request.FilePath, Me.Request.Url.ToString, q.ToString)

Only this doesn't work, q.ToString returns
"System.Collections.Specialized.NameValueCollectio n". Do I really
have to serialize the QueryString myself? Is there really no built-in
method to do this?


It doesn't really make a lot of sense to change a property of a request
you've already received (except debugging and testing).

Any object you might want to associate with a particular request at
this point in time can be passed by SessionState or HttpContext.

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 19 '05 #4
On Thu, 10 Nov 2005 13:10:16 -0500, PJ6 wrote:
Try perhaps Response.Redirect if you want to direct the browser to a new
page and/or with a new querystring...


And - to repeat my qestion - can one build this new query string using the
built-in object model, or does the logic for this have to be coded by hand?

Paul

Not that I know of. However, why don't you render a client-side hidden
field? It will be included in the QueryString
Nov 19 '05 #5
> It doesn't really make a lot of sense to change a property of a request
you've already received (except debugging and testing).

Any object you might want to associate with a particular request at
this point in time can be passed by SessionState or HttpContext.


Actually, it makes perfect sense in certain circumstances. Let's say
you want to change the behavior of an entire site in some universal way
without having to re-code the entire thing. Let's say you want to be
able to send in one querystring parm to the site, say "Mode2", and have
the site use a different stylesheet if "Mode2" is in the Querystring.

Well, that's all fine and dandy, but what happens the second you click
a link on the site? That parm and its value will be lost and the site
will switch back to the other stylesheet. If there was a way to check
the referrer and add the querystring to the current request if it was
present in the referrer, the value could be propagated at a high level,
and no other code would need to be changed. It would be like a
persistent querystring item - once present, always present. I wanted
to do this to provide my users a way to surf their site using a totally
different stylesheet without having to re-code the entire site to
handle new functionality.

I can think of other uses for this as well, but alas I haven't found a
good way to do it.

Dec 3 '05 #6
Well, writing that description got me thinking on the problem again,
and I solved it the best way I can think of. For my specific scenario,
I just put a check at the very beginning of Application_BeginRequest to
look for the parm. If it's not found, I check the referrer. If it's
found there, I immediately do a redirect, adding the parm.

This works well as long as the referrer is intact. Unfortunately, I've
got a third party navigation control that's clearing it out.

Dec 4 '05 #7
Ferret wrote:
It doesn't really make a lot of sense to change a property of a
request you've already received (except debugging and testing).

Any object you might want to associate with a particular request at
this point in time can be passed by SessionState or HttpContext.


Actually, it makes perfect sense in certain circumstances. Let's say
you want to change the behavior of an entire site in some universal
way without having to re-code the entire thing. Let's say you want
to be able to send in one querystring parm to the site, say "Mode2",
and have the site use a different stylesheet if "Mode2" is in the
Querystring.

Well, that's all fine and dandy, but what happens the second you click
a link on the site? That parm and its value will be lost and the site
will switch back to the other stylesheet. If there was a way to check
the referrer and add the querystring to the current request if it was
present in the referrer, the value could be propagated at a high
level, and no other code would need to be changed. It would be like a
persistent querystring item - once present, always present. I wanted
to do this to provide my users a way to surf their site using a
totally different stylesheet without having to re-code the entire
site to handle new functionality.


All of that can be easily done using cookies or a some object in the
user's session. Heck, you could even do that with query strings. Of
course not for the current request, but all subsequent ones -- append
the key Mode2 to each and every URL you render in your pages... ouch ;-)

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Dec 6 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ben Hallert | last post by:
Hi guys, I'm trying to figure out what bone headed mistake I made on something I put together. I've got a form (named 'context') that has a variable number of select-multiple inputs on it. ...
0
by: Anders Borum | last post by:
Hello! I would like to request a new method on the XsltArgumentList class, allowing developers to check the presense of a key/value pair. If you try to add a key/value pair that has already been...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
2
by: Hazzard | last post by:
I am trying to figure out how to add an additional value to a querystring collection so that when I click on a datagrid cell, there will be a key to distinguish it from another column's...
6
by: Joe | last post by:
Hello All: I have a webform (WebForm1.aspx) that retrieves a value from a database (_formSessionId) the first time that it is posted. After the user filles in the form, he/she clicks a Button...
5
by: Neo Geshel | last post by:
Greetings. I am in a very big pickle. I am trying to add page content - as well as a submit button - programatically to a web form that is supposed to submit to DB and then refresh. That...
9
by: Neo Geshel | last post by:
I have strip-mined, strip-searched, and completely exhausted the Internet (up to the 30th page on Google, with 100 results per page!!), all without finding an answer to my question AS TO WHY IT...
1
by: Mo | last post by:
Hi, I am having a lot of problem adding a parameter to a oledb data sorce and execute it here is what I have I call string Pump="Yes" ResultSet = RunQuery("Update CDB_on set Resultx=:Resultx...
5
by: magix8 | last post by:
Hi, I have form GET method, example: index.asp?Type=1&Type=3&Type=4&.... So, I have something like this at the receiver side to retrieve multiple Type value and insert into tables.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.