i have made a helper Method using it to modify Query Strings, for testing and debugging
the only problem now is that i would like to make it as a Class in my
C# collection helper-class
the method is working perfectly now , but as i am still “fresh” .net developer
i couldn’t figure out how to use
this.Request.QueryString to access current partial class – form (form1)
values when it’s inside a separated public static or non static class
this is the code , you’re free to use it (:
public void QsModify(string action, string NewP_Value, string CurQS_ParamName, string NewQs_paramName=null, bool redirectWithNewQuerySettings=false)
{
#region <<=========== reflect to readonly & set QueriString ReadOnly - false ============>>
// reflect to readonly property
PropertyInfo isReadOnly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
// make collection editable
isReadOnly.SetValue(this.Request.QueryString, false, null);
#endregion
switch (action)
{
case ModAQs_Remove:
if (notEmptyQs())
this.Request.QueryString.Remove(CurQS_ParamName);
break;
case ModAQs_Replace:
this.Request.QueryString.Remove(CurQS_ParamName);
this.Request.QueryString.Add(NewQs_paramName, NewP_Value);
break;
case ModAQs_EditValue:
this.Request.QueryString.Set(CurQS_ParamName, NewP_Value);
break;
case ModAQs_Add:
this.Request.QueryString.Add(NewQs_paramName, NewP_Value);
break;
}
#region <<=========== joining Full Path & queryString then Redirection ============>>
string seperator = "?";
UrlPath = Request.Url.AbsolutePath;
UrlPathAndQuery = string.Join(seperator, UrlPath, this.Request.QueryString);
isReadOnly.SetValue(this.Request.QueryString, true, null);
if (redirectWithNewQuerySettings)
{
Response.Redirect(UrlPathAndQuery);
}
#endregion
}
how do i make it into a class that will be able to access any project i am working on
not knowing what the form name will be
You can use
You can use it either in static or non-static contexts.