Clearing QueryString Name/Value pair from URL

J

Jon

Hi,

I have hyperlink objects in a datagrid that redirect the user back to
the current page with this syntax:
<a href="mypage.aspx?id=foo">

When the page reloads, code in Page_Load then takes the appropriate
action based on finding the 'id' name/value pair in the URL
querystring. This works well.

However, I've noticed that all subsequent posts back to the page
retain the querystring. So if a user presses another button on the
form, .NET reposts this URL: mypage.aspx?id=foo (and my page_load
code is executed again).

What I'd like to do is remove the querystring ('?id=foo') from the URL
that .NET uses on all following post backs. I tried to do this
through some of the Request objects but had no luck (most were read
only).

Does anyone know how to modify the querystring or header stored by
..NET that's used for post back events?

~ Jon
 
D

dm_dal

Jon,
To clear all querystrings, you can call the Request.QueryString.Clear();
To remove a specific querystring call: Request.QueryString.Remove(foo),
where foo is the string containing the name of the querystring to remove;

In your case it would be: Request.QueryString.Remove("id");

David Young
 
B

bruce barker

rahter than try to remove the query string, just ignore it on a postback
(IsPostback).

-- bruce (sqlwork.com)
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top