#region Private Properties string[] _formKeys; string[] _queryStringKeys; #endregion #region Web Page Properties /// <summary> A list of keys found in Request.Form </summary> protected string[] FormKeys { get { if (this._formKeys == null) this._formKeys = Request.Form.AllKeys; return this._formKeys; } } /// <summary> A list of keys found in Request.QueryString </summary> protected string[] QueryStringKeys { get { if (this._queryStringKeys == null) this._queryStringKeys = Request.QueryString.AllKeys; return this._queryStringKeys; } } #endregion #region public methods ///<summary>Grabs parameter from Form or Query String. Never returns NULL.</summary> /// <param name="paramName">The name of the parameter to be pulled</param> /// <returns>Value of parameter. Returns String.Empty if no value or parameter found.</returns> protected string requestParam(string paramName) { string result = requestParam(paramName, false); return (result == null) ? String.Empty : result.Trim(); } ///<summary>Grabs parameter from Form or Query String. </summary> /// <param name="paramName">The name of the parameter to be pulled</param> /// <param name="returnNullIfParamNotFound">Will return NULL if parameter was not passed in the form or query string. If false an empty string will be returned.</param> /// <returns>Value of parameter. Returns String.Empty parameter found but has no value.</returns> /// <returns></returns> protected string requestParam(string paramName, bool returnNullIfParamNotFound) { string result = String.Empty; if (Context.Request.Form.Count != 0) { result = Convert.ToString(Context.Request.Form[paramName]); } if (Context.Request.QueryString.Count != 0 && (result == String.Empty || result == null)) { result = Convert.ToString(Context.Request.QueryString[paramName]); } if (result == null && returnNullIfParamNotFound) { // check the form keys if (stringFoundInArray(this.FormKeys, paramName)) return string.Empty; //doing a return to skip the rest // check the query string keys if (stringFoundInArray(this.QueryStringKeys, paramName)) return string.Empty; } return result; } /// <summary> /// Performs a case insensitive search of an string array for a value /// </summary> /// <param name="array"></param> /// <param name="value"></param> /// <returns>Boolean indicating if value was found or not</returns> public static bool stringFoundInArray(string[] array, string value) { for (int x = 0; x < array.Length; x++) if (string.Equals(value, array[x], StringComparison.OrdinalIgnoreCase)) return true; return false; } #endregion
You need to create an account or log in to post comments to this site.