Tuesday, January 24, 2012

How to Reset/Remove read only property values in C#


How to remove query string from the url.
Example: In this example Query String value is setting to the null then it is removed from the query string:
            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.Set(keyname,null);
                HttpContext.Current.Request.QueryString.Remove(keyname);
            }

Note: PropertyInfo class will exist under “System.Reflection” namespace

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.
    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

    ReplyDelete