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

Removing Items From QueryString

P: n/a
A.M
Hi,

When I call
Request.QueryString.Clear();

ASP.NET throws me this exception:

Exception Details: System.NotSupportedException: Collection is read-only

If the collection is read-onle, then why there is a Clear() method?

If I can not call Clear() methid in certain phases of QueryString's life
time, then how can I remove items from QueryString during postbacks?

Thanks,
Alan
Nov 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
The collection is readonly which means you can't modify it. Not at all - not
directly or indirectly.

The querystring can't be controlled from within the code, because by the
time your code fired it is already passed to you. This makes perfect sense
if you think about it <g>...

I'm guessing you want to modify the URL of the page? The only way to do this
is to Redirect to another page or possibly using some client script to
modify the Location. ASP.Net always posts back to the same URL and you
cannot change that from the server side...

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web
"A.M" <no*****@online.nospam> wrote in message
news:Of**************@TK2MSFTNGP11.phx.gbl...
Hi,

When I call
Request.QueryString.Clear();

ASP.NET throws me this exception:

Exception Details: System.NotSupportedException: Collection is read-only

If the collection is read-onle, then why there is a Clear() method?

If I can not call Clear() methid in certain phases of QueryString's life
time, then how can I remove items from QueryString during postbacks?

Thanks,
Alan

Nov 18 '05 #2

P: n/a
Hi Alan,

I think Rick has provided enough information to you. What I want to tell is
that the Clear() method is a member of NameValueCollection class, which is
for general use.(HttpRequest.QueryString property return a
NameValueCollection object). While QueryString can not be modified by you,
so the Clear method can not be used.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #3

P: n/a
Hi Alan,

Does our reply make sense to you? Do you still have concern on this issue?

Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #4

P: n/a
A.M
Thank you Jeffrey,

That Clear method confused me. It does make sense QueryString be readonly.

However, technically, It should be quite doable to change QueryString by
*during post backs *. What do you think?


""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:aq**************@cpmsftngxa10.phx.gbl...
Hi Alan,

Does our reply make sense to you? Do you still have concern on this issue?

Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #5

P: n/a
A.M

I think you missed one point,

Technically, It should be quite doable to change QueryString *during post
backs *

Is it implemented in ASP.NET?

"Rick Strahl [MVP]" <ri********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
The collection is readonly which means you can't modify it. Not at all - not directly or indirectly.

The querystring can't be controlled from within the code, because by the
time your code fired it is already passed to you. This makes perfect sense
if you think about it <g>...

I'm guessing you want to modify the URL of the page? The only way to do this is to Redirect to another page or possibly using some client script to
modify the Location. ASP.Net always posts back to the same URL and you
cannot change that from the server side...

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web
"A.M" <no*****@online.nospam> wrote in message
news:Of**************@TK2MSFTNGP11.phx.gbl...
Hi,

When I call
Request.QueryString.Clear();

ASP.NET throws me this exception:

Exception Details: System.NotSupportedException: Collection is read-only

If the collection is read-onle, then why there is a Clear() method?

If I can not call Clear() methid in certain phases of QueryString's life
time, then how can I remove items from QueryString during postbacks?

Thanks,
Alan


Nov 18 '05 #6

P: n/a
A PostBack is simply an HTTP Request using the POST method, rather than the
GET method. The Query String is still read-only. The only way to change the
Query String is to Response.Redirect, which tells the browser to Request the
new URL you send it, with the parameters it has in it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"A.M" <no*****@online.nospam> wrote in message
news:#A**************@TK2MSFTNGP10.phx.gbl...
Thank you Jeffrey,

That Clear method confused me. It does make sense QueryString be readonly.

However, technically, It should be quite doable to change QueryString by
*during post backs *. What do you think?


""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:aq**************@cpmsftngxa10.phx.gbl...
Hi Alan,

Does our reply make sense to you? Do you still have concern on this issue?
Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.