Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
 
Add your own
alternative version
Go to top

Declarative QueryString Parameter Binding

, 2 Mar 2004
Describes using reflection to automatically populate member parameters from the Form and Querystring.
<%@ Page language="c#" Codebehind="WebParameterDemo.aspx.cs" AutoEventWireup="false" Inherits="WebControlTestWeb.WebParameterDemo" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>BoundParameterDemo</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
		<meta name="CODE_LANGUAGE" Content="C#">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
	</HEAD>
	<body>
		<form id="BoundParameterDemo" method="get" runat="server">
			<H1>QueryString parameter binding demo</H1>
			<P>Using the WebParameter attribute, the <STRONG>FirstName</STRONG> and&nbsp;<STRONG>CustomerID</STRONG>
				fields in the underlying page class are 'bound' to <STRONG>txtFirstName</STRONG>
				and&nbsp;<STRONG>txtCustomerID</STRONG> in the querystring. Additionally the 
				property <STRONG>LastName</STRONG> is bound to <STRONG>txtLast_Name</STRONG> in 
				the querystring.</P>
			<P>In Page_Load the&nbsp;fields/properties are loaded from the querystring, 
				and&nbsp;the two fields&nbsp;values&nbsp;and the property value are 
				assigned&nbsp;to the controls.
			</P>
			<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" border="1">
				<TR>
					<TD>First Name</TD>
					<TD>
						<INPUT type="text" runat="server" id="txtFirstName"></TD>
				</TR>
				<TR>
					<TD>Last Name</TD>
					<TD>
						<INPUT id="txtLastName" type="text" runat="server"></TD>
				</TR>
				<TR>
					<TD>Customer ID</TD>
					<TD>
						<INPUT id="txtCustomerID" type="text" runat="server"></TD>
				</TR>
				<TR>
					<TD></TD>
					<TD align="right">
						<INPUT type="submit" value="Submit"></TD>
				</TR>
			</TABLE>
			<P>I should stress that this <EM>isn't</EM> advocating an alternative mechanism for 
				loading data into controls after postback - this rather contrived demo is 
				purely to demonstrate that the concept works. A far more&nbsp;common use would 
				be to handle a (non postback)&nbsp;query request like (for example):</P>
			<P>http://somesite/showAccounts.aspx?accountBalanceMin=120&amp;StartDate=2003/01/01&amp;EndDate=2004/01/01</P>
			<P>&nbsp;</P>
		</form>
	</body>
</HTML>

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.

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 3 Mar 2004
Article Copyright 2004 by piers7
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid