//------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //------------------------------------------------------------------------------ namespace System.Web.UI.WebControls { using System; using System.Collections.Specialized; using System.ComponentModel; using System.Data; /// /// Represents a Parameter that gets its value from the application's QueryString parameters. /// [ DefaultProperty("QueryStringField"), ] public class QueryStringParameter : Parameter { /// /// Creates an instance of the QueryStringParameter class. /// public QueryStringParameter() { } /// /// Creates an instance of the QueryStringParameter class with the specified parameter name and QueryString field. /// public QueryStringParameter(string name, string queryStringField) : base(name) { QueryStringField = queryStringField; } /// /// Creates an instance of the QueryStringParameter class with the specified parameter name, database type, /// and QueryString field. /// public QueryStringParameter(string name, DbType dbType, string queryStringField) : base(name, dbType) { QueryStringField = queryStringField; } /// /// Creates an instance of the QueryStringParameter class with the specified parameter name, type, and QueryString field. /// public QueryStringParameter(string name, TypeCode type, string queryStringField) : base(name, type) { QueryStringField = queryStringField; } /// /// Used to clone a parameter. /// protected QueryStringParameter(QueryStringParameter original) : base(original) { QueryStringField = original.QueryStringField; ValidateInput = original.ValidateInput; } /// /// The name of the QueryString parameter to get the value from. /// [ DefaultValue(""), WebCategory("Parameter"), WebSysDescription(SR.QueryStringParameter_QueryStringField), ] public string QueryStringField { get { object o = ViewState["QueryStringField"]; if (o == null) return String.Empty; return (string)o; } set { if (QueryStringField != value) { ViewState["QueryStringField"] = value; OnParameterChanged(); } } } /// /// Creates a new QueryStringParameter that is a copy of this QueryStringParameter. /// protected override Parameter Clone() { return new QueryStringParameter(this); } /// /// Returns the updated value of the parameter. /// protected internal override object Evaluate(HttpContext context, Control control) { if (context == null || context.Request == null) { return null; } NameValueCollection queryStringCollection = ValidateInput ? context.Request.QueryString : context.Request.Unvalidated.QueryString; return queryStringCollection[QueryStringField]; } /// /// Determines whether the parameter's value is being validated or not. /// [ WebCategory("Behavior"), WebSysDescription(SR.Parameter_ValidateInput), DefaultValue(true) ] public bool ValidateInput { get { object o = ViewState["ValidateInput"]; if (o == null) return true; return (bool)o; } set { if (ValidateInput != value) { ViewState["ValidateInput"] = value; OnParameterChanged(); } } } } }