[英]this.QueryString (NameValueCollection) access Form1 - from another class
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 现在唯一的问题是我想将其作为C#集合帮助器类中的类
the method is working perfectly now , but as i am still "fresh" .net developer 该方法现在可以正常工作,但是由于我仍然是“新鲜”的.net开发人员
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.Request.QueryString
来访问当前的partial class
-在单独的公共静态或非静态类内时形成(form1)值
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 您可以使用
HttpContext.Current.Request.QueryString["qs_key"];
You can use it either in static or non-static contexts. 您可以在静态或非静态上下文中使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.