Friday, November 26, 2010

Removing(Deleting) Querystring in code

Problem

Request.QueryString.Remove("foo")

If u r removing just like this will not work. U will get error states that 'collection is read-only'.

Solution

So the solution is, before deleting the querystring u need to write the below code.

In C#,
PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);

// make collection editable
isreadonly.SetValue(this.Request.QueryString, false, null);

// remove
this.Request.QueryString.Remove("foo");


In VB,
Dim isreadonly As PropertyInfo = GetType(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance Or BindingFlags.NonPublic)

' make collection editable
isreadonly.SetValue(Me.Request.QueryString, False, Nothing)

' remove
Me.Request.QueryString.Remove("foo")


Now try. It will work. have a great day. Enjoy....

Tuesday, November 2, 2010

Photo Viewer

The index will go here.Slideshow Mode (10 second delay):On / OffPrevious Next
PhotoCaption