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"]);
}
}
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
Technorati tags: asp.net, asp.net2.0, c#, programming, webdevelopment, web, querystring, javascript, asp.net 2.0, code
.
October 30th, 2007 at 9:01 am
[...] 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 [...]