asp.net.ph

CookieParameter Class

System.Web.UI.WebControls Namespace


.NET Framework version 2.0

Binds the value of a client-side HTTP cookie to a parameter object. The parameter can be used in a parameterized query or command to select, filter, or update data.

CookieParameter Class Members

Collapse   Constructors

Visibility Constructor Parameters
public CookieParameter ( )
public CookieParameter ( String name , String cookieName )
public CookieParameter ( String name , DbType dbType , String cookieName )
public CookieParameter ( String name , TypeCode type , String cookieName )

Collapse   Properties

Visibility Name Value Type Accessibility
public CookieName String [ Get , Set ]
public ValidateInput Boolean [ Get , Set ]

Collapse   Methods

Visibility Name Parameters Return Type
protected Clone ( ) Parameter

Remarks

You can use the CookieParameter class to bind the value of a client-side HTTP cookie passed as part of an HTTP request to a parameter used by ASP.NET data source controls.

The CookieParameter class provides the CookieName property, which identifies the name of the HttpCookie object to bind to, in addition to those inherited from the Parameter class. The CookieParameter class attempts to bind to the named cookie every time the Evaluate method is called.

IMPORTANT: Controls that bind data to the parameter might throw an exception if a CookieParameter object is specified, but no corresponding cookie is passed with the HTTP request. Similarly, they might display no data if the cookie is passed with a null reference (Nothing in Visual Basic). Set the DefaultValue property to avoid these situations where appropriate.

Example

The following example demonstrates how to use a SqlDataSource control and CookieParameter object bound to an HTTP cookie to display data from the Northwind Traders database in a GridView control.

<script language = "C#" runat = "server">
   void Page_Load(Object src, EventArgs e){
      // These cookies might be added by a login form.
      // They are added here for simplicity.
      if ( !IsPostBack ) {
         Response.Cookies.Add ( new HttpCookie ( "lname", "davolio" ) );
         Response.Cookies.Add ( new HttpCookie ( "loginname", "ndavolio" ) );
         Response.Cookies.Add ( new HttpCookie ( "lastvisit", DateTime.Now.ToString ( ) ) );
      }
   }
</script>

<asp:sqldatasource id = "SalesByEmployee" runat = "server"
   SelectCommand = "SELECT OrderID, OrderDate, CustomerID, ShipAddress, ShipCity, ShipCountry 
      FROM Orders 
      WHERE EmployeeID = ( SELECT EmployeeID FROM Employees WHERE LastName = @lastname )"
   connectionstring = "<%$ ConnectionStrings:aspnet %>">

   <selectparameters>
      <asp:cookieparameter name = "lastname" cookiename = "lname" />
   </selectparameters>

</asp:sqldatasource>

<asp:gridview id = "ordersGrid" runat = "server"
   width=90% cellpadding=3 font-size=8pt
   datasourceid = "SalesByEmployee"
   allowsorting allowpaging>

   <headerstyle backcolor = "lightsteelblue" height=20pt />
   <alternatingrowstyle backcolor = "whitesmoke" />

</asp:gridview>

 Show me 

See Also

Using Parameters with Data Source Controls Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph