mhinze.com archive

this is an archive of the old blog, ended 6/16/08





    28
    Mar

    clear or remove query string on postback… nifty but ghetto

     
     
    if (!Page.IsPostBack)
    {
       // set defaults, hide yer panels, etc here
    
       if (Request.QueryString["q"] != null) // if the query string exists
       {
           // aspnetForm - default masterpage form name, YourPage.aspx - whatever your page name is
           ClientScript.RegisterStartupScript(this.GetType(), "qr", 
                "document.all(\"aspnetForm\").action = \"YourPage.aspx\";", true);

           // do stuff with query string
           RedrawPage(Request.QueryString["q"]);
       }
    }

     

    via msdn

     

    so if you have a page that accepts a query string, you definitely want to set that view

    but this is asp.net, so your page also posts back

    you don't want the query string to persist across postbacks - that's just ugly, breaking bookmarks, etc.  you want to clear the query string but maybe you are trying Clear() or Remove() and you are realizing that Request.QueryString is Read Only..

    one option is to set the form's action in client script (Googlebot's not posting back anyway)

    is there a better way to do this?  it seems so ghetto

    by the way, comments on this blog are NOT nofollowed

     

    .

    One Response to “clear or remove query string on postback… nifty but ghetto”

    1. No More ASP.NET » Blog Archive » Clear QueryStrings in ASP.NET Says:

      [...] partially right: it does take some client-based code, but it, in my opinion, isn't screwy or ghetto (as one person called it–whom I also pilfered the idea from). It is, in fact, pretty elegant [...]

    Leave a Reply

    You must be logged in to post a comment.

    © 2007 mhinze.com