I wanted to make my page behave in two different modes based on the query string. However it was not strait forward. To make it possible I had to manipulate the URL query string to and remove a key and redirecting it back with a freshly creating URL.
Calling Page
bool isKeyFound = false;
string newQueryString = AppHelper.GetNewQueryString (Request.QueryString,"refresh", out isKeyFound);
if (isKeyFound && newQueryString.Length > 0)
{
Response.Redirect(Request.Path + "?" +newQueryString);
}
Called Method
public static string GetNewQueryString(System.Collections.Specialized.NameValueCollection queryString, string removeKey,out bool isKeyFound)
{
string returnVal = string.Empty;
isKeyFound = false ;
for (int j = 0; j < queryString.Count; j++)
{
if (!queryString.GetKey(j).ToLower().Equals(removeKey.ToLower()))
{
returnVal += queryString.GetKey(j) + "=" + queryString.Get(j) + "&";
}
else
{
isKeyFound = true;
}
}
return returnVal.TrimEnd ('&');
}
Happy coding