update the Querystring without Page Reload or Refresh

using System.Reflection;

string sCurrentValue = Request.QueryString[“QueryParam”];
            PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty(“IsReadOnly”, BindingFlags.Instance | BindingFlags.NonPublic);
            // make collection editable
            if (HttpContext.Current.Request != null)
                // remove
                isreadonly.SetValue(HttpContext.Current.Request.QueryString, false, null);
                HttpContext.Current.Request.QueryString.Remove(“QueryParam=” + sCurrentValue);
                HttpContext.Current.Request.QueryString.Set(“QueryParam”, newValue);
                isreadonly.SetValue(HttpContext.Current.Request.QueryString, true, null);


here ”  isreadonly.SetValue(HttpContext.Current.Request.QueryString, false, null); “

Second Parameter false set the readonly property to false. Now you can change the value of readonly property.
In the last line i set the readonly property back to true to avoid security threat.

Share the joy

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.