Clear QueryString on PostBack?

Discussion in 'ASP .Net' started by Raterus, May 28, 2004.

  1. Raterus

    Raterus Guest

    Howdy,

    Simple question, but I can't figure out how to do it. I have a a page which is called initially with a querystring. After I get the querystring values, I don't need the querystring to appear in the url anymore. How can I get rid of it? A postback doesn't clear it, it just keeps tagging along. I tried Request.QueryString.Clear, but get "readonly" errors.

    I want to do this, because eventually I use server.transfer within this page, and the querystring, tags along to new page as well, even after a postback on this new page. I start to get problems when, from second page, I perform a server.transfer back to the first page. My problems are explainable, if the querystring was empty, the page would work properly, but since the querystring is set, my page essentially breaks. I'm not too concerned about this, because if I could get rid of the querystring, I wouldn't have this problem!

    Thanks for any help on this,
    --Michael
     
    Raterus, May 28, 2004
    #1
    1. Advertising

  2. Michael,

    The Server.Transfer method has an overload that allows you to specify
    whether the querystring and form data should be preserved or not. Using
    this appropriately should give the result you desire. Otherwise, might a
    client-side redirection work for at least one of your two transfers?

    HTH,
    Nicole


    "Raterus" <> wrote in message
    news:...
    Howdy,

    Simple question, but I can't figure out how to do it. I have a a page which
    is called initially with a querystring. After I get the querystring values,
    I don't need the querystring to appear in the url anymore. How can I get
    rid of it? A postback doesn't clear it, it just keeps tagging along. I
    tried Request.QueryString.Clear, but get "readonly" errors.

    I want to do this, because eventually I use server.transfer within this
    page, and the querystring, tags along to new page as well, even after a
    postback on this new page. I start to get problems when, from second page,
    I perform a server.transfer back to the first page. My problems are
    explainable, if the querystring was empty, the page would work properly, but
    since the querystring is set, my page essentially breaks. I'm not too
    concerned about this, because if I could get rid of the querystring, I
    wouldn't have this problem!

    Thanks for any help on this,
    --Michael
     
    Nicole Calinoiu, May 28, 2004
    #2
    1. Advertising

  3. Raterus

    Raterus Guest

    Never knew it had that option, but unfortunately that doesn't help, as the default is "false".
    I think my more explain my problem now by this example, take server.transfer out of it. After my page that uses the querystring is rendered, this appears in the html source. The postback uses the querystring, I don't want it to.

    <form name="Form1" method="post" action="manage.aspx?docID=40" id="Form1">
    I want it to say this
    <form name="Form1" method="post" action="manage.aspx" id="Form1">

    Any ideas how I can clear the querystring from being rendered like this?

    --Michael

    "Nicole Calinoiu" <> wrote in message news:...
    > Michael,
    >
    > The Server.Transfer method has an overload that allows you to specify
    > whether the querystring and form data should be preserved or not. Using
    > this appropriately should give the result you desire. Otherwise, might a
    > client-side redirection work for at least one of your two transfers?
    >
    > HTH,
    > Nicole
    >
    >
    > "Raterus" <> wrote in message
    > news:...
    > Howdy,
    >
    > Simple question, but I can't figure out how to do it. I have a a page which
    > is called initially with a querystring. After I get the querystring values,
    > I don't need the querystring to appear in the url anymore. How can I get
    > rid of it? A postback doesn't clear it, it just keeps tagging along. I
    > tried Request.QueryString.Clear, but get "readonly" errors.
    >
    > I want to do this, because eventually I use server.transfer within this
    > page, and the querystring, tags along to new page as well, even after a
    > postback on this new page. I start to get problems when, from second page,
    > I perform a server.transfer back to the first page. My problems are
    > explainable, if the querystring was empty, the page would work properly, but
    > since the querystring is set, my page essentially breaks. I'm not too
    > concerned about this, because if I could get rid of the querystring, I
    > wouldn't have this problem!
    >
    > Thanks for any help on this,
    > --Michael
    >
    >
     
    Raterus, May 28, 2004
    #3
  4. =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=, May 28, 2004
    #4
  5. Raterus

    bruce barker Guest

    the only way to clear the querystring is a redirect. the browser does not
    know you do a server transfer, it just remembers what the url (including
    query string) was for the postback. to clear it you send the browser a
    redirect, so that the new rendered page matchs the new url.

    -- bruce (sqlwork.com)


    "Raterus" <> wrote in message
    news:...
    Howdy,

    Simple question, but I can't figure out how to do it. I have a a page which
    is called initially with a querystring. After I get the querystring values,
    I don't need the querystring to appear in the url anymore. How can I get
    rid of it? A postback doesn't clear it, it just keeps tagging along. I
    tried Request.QueryString.Clear, but get "readonly" errors.

    I want to do this, because eventually I use server.transfer within this
    page, and the querystring, tags along to new page as well, even after a
    postback on this new page. I start to get problems when, from second page,
    I perform a server.transfer back to the first page. My problems are
    explainable, if the querystring was empty, the page would work properly, but
    since the querystring is set, my page essentially breaks. I'm not too
    concerned about this, because if I could get rid of the querystring, I
    wouldn't have this problem!

    Thanks for any help on this,
    --Michael
     
    bruce barker, May 28, 2004
    #5
  6. Raterus

    mrawlingson

    Joined:
    Jun 24, 2009
    Messages:
    1
    I know I'm a bit late on this one, but for those stumbling across this - you can change the action attribute using Form.Action in your code behind

    Sample code:

    if (request.querystring == "something") {
    //do something
    Form.Action = "this page.aspx";
    }

    So any time there is a further postback or any submission of the form, your querysting won't be carried over.
     
    mrawlingson, Jun 24, 2009
    #6
  7. Raterus

    malbert1169

    Joined:
    Sep 17, 2010
    Messages:
    1
    This works PERFECTLY! Thank you, mrawlingson.

     
    malbert1169, Sep 17, 2010
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Davids

    How to clear the querystring?

    Davids, Nov 10, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    9,962
    Patrice
    Nov 15, 2004
  2. Mehdi
    Replies:
    6
    Views:
    36,217
    sloan
    Apr 6, 2006
  3. David

    Response.Clear() doesn't clear

    David, Jan 31, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    1,091
    Mark Fitzpatrick
    Jan 31, 2008
  4. InvalidLastName

    Unrecognized element 'add' after <clear></clear>

    InvalidLastName, Feb 26, 2007, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    1,037
    Steven Cheng[MSFT]
    Mar 6, 2007
  5. Adeel Ahmad
    Replies:
    1
    Views:
    578
    Anthony Jones
    Mar 7, 2006
Loading...

Share This Page