Click here to Skip to main content
12,292,562 members (66,246 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads

Stats

192.1K views
1.1K downloads
95 bookmarked
Posted

Declarative QueryString Parameter Binding

, 2 Mar 2004
Describes using reflection to automatically populate member parameters from the Form and Querystring.
using System;

namespace piers7.Web.Controls
{
	/// <summary>
	/// A <see cref="WebParameterAttribute"/> that's specifically bound to the
	/// a parameter in the http POST (Request.Form collection)
	/// </summary>
	[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple=false, Inherited=true)]
	public sealed class FormParameterAttribute : WebParameterAttribute
	{
		#region Constructors
		/// <summary>
		/// Creates a new FormParameterAttribute to load a field from an identically-named
		/// parameter in the Form collection, if it exists.
		/// The parameter has no default value, and is not required
		/// </summary>
		public FormParameterAttribute() {
		}

		/// <summary>
		/// Creates a new FormParameterAttribute to load a field from the given parameter
		/// in the Form collection, if it exists.
		/// The parameter has no default value, and is not required
		/// </summary>
		/// <param name="paramName">The key of a parameter in the Form collections</param>
		public FormParameterAttribute(string paramName) : base(paramName) {
	}
		#endregion

		/// <summary>
		/// Retrieves an item from the Form collection by key
		/// </summary>
		protected override string GetValue(string paramName, System.Web.HttpRequest request)
		{
			return request.Form[paramName];
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

piers7
Web Developer
Australia Australia
There's some kinda mutex between money and the time to enjoy it, and it's called work.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160518.1 | Last Updated 3 Mar 2004
Article Copyright 2004 by piers7
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid