views:

962

answers:

7

I have a form that sometimes gets linked to with some query string parameters. The problem is that when I post back the form, the query string parameter is still there. Its not really an issue the way I have it setup, but I just don't like it being there, and could see it being a problem if you needed to check for input in a certain order.

Is there a way to clear that query string parameter in an easy, clean way? I know I could change the PostBackURL on the button, but that doesn't seem to efficient.

+2  A: 

No, I haven't seen a way to clear it out without a redirect.

rvarcher
same here .
Greg B
Is there a clean way to do a Response.Redirect() to the page you're currently on?
SkippyFire
Try: Response.Redirect(Request.CurrentExecutionFilePath())
rvarcher
A: 

You can in some cases use the Server.Transfer() method, which has an overload that allows you to specify whether the querystring and form data should be preserved or not.

meep
+1  A: 

put this at the bottom of your page?

<script language="javascript" type="text/javascript">
    document.forms[0].action = window.location.pathname;
</script>
Al W
+1  A: 

I think you've answered your own question. Use the PostBackURL property.

<asp:Button PostBackUrl='<%# Request.ServerVariables["URL"] %>' runat="server" Text="Submit" />

Or something like

foreach (Control ctrl in Page.Controls)
{
    if (ctrl is Button)
    {
        ((Button)ctrl).PostBackUrl = Request.ServerVariables["URL"];
    }
}
Axl
+1  A: 

I assume that you can't rely on Page.IsPostBack for some reason?

If what you're doing is server-side, then it's simple to add a check for IsPostBack in your methods (Page_Load, OnInit, etc) and only processing the querystrings if it's not a post back (i.e. the initial request).

Zhaph - Ben Duguid
A: 
Miguel
A: 

OK.. thanks. It's works.

Roberto