CookieParameter Constructors
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the CookieParameter class.
Overloads
CookieParameter() |
Initializes a new unnamed instance of the CookieParameter class. |
CookieParameter(CookieParameter) |
Initializes a new instance of the CookieParameter class with the values of the instance specified by the |
CookieParameter(String, String) |
Initializes a new named instance of the CookieParameter class, using the specified string to identify which HTTP cookie to bind to. |
CookieParameter(String, DbType, String) |
Initializes a new instance of the CookieParameter class that has the specified name and database type and that is bound to the specified HTTP cookie. |
CookieParameter(String, TypeCode, String) |
Initializes a new named and strongly typed instance of the CookieParameter class, using the specified string to identify which HTTP cookie to bind to. |
CookieParameter()
Initializes a new unnamed instance of the CookieParameter class.
public:
CookieParameter();
public CookieParameter ();
Public Sub New ()
Examples
The following code example demonstrates how to create a CookieParameter object using the CookieParameter constructor, set its Name, Type, and CookieName properties, and then add it to a SqlDataSource control's SelectParameters collection.
<%@ Page Language="C#" CodeFile="cookieparam2cs.aspx.cs" Inherits="cookieparam2cs_aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource
id="SqlDataSource1"
runat="server"
DataSourceMode="DataSet"
ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
selectcommand ="SELECT OrderID,CustomerID,OrderDate,RequiredDate,ShippedDate
FROM Orders WHERE EmployeeID =
(SELECT EmployeeID FROM Employees WHERE LastName = @lastname)">
</asp:SqlDataSource>
<asp:GridView
id="GridView1"
runat="server"
AllowSorting="True"
DataSourceID="SqlDataSource1">
</asp:GridView>
</div>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="cookieparam2vb.aspx.vb" Inherits="cookieparam2vb_aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource
id="SqlDataSource1"
runat="server"
DataSourceMode="DataSet"
ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
selectcommand ="SELECT OrderID,CustomerID,OrderDate,RequiredDate,ShippedDate
FROM Orders WHERE EmployeeID =
(SELECT EmployeeID FROM Employees WHERE LastName = @lastname)">
</asp:SqlDataSource>
<asp:GridView
id="GridView1"
runat="server"
AllowSorting="True"
DataSourceID="SqlDataSource1">
</asp:GridView>
</div>
</form>
</body>
</html>
The following code-behind module is used with the previous Web Forms page.
public partial class cookieparam2cs_aspx : System.Web.UI.Page
{
void Page_Load(Object sender, 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()));
// You can add a CookieParameter to the SqlDataSource control's
// SelectParameters collection programmatically.
CookieParameter cookieParam = new CookieParameter();
cookieParam.Name = "lastname";
cookieParam.Type = TypeCode.String;
cookieParam.CookieName = "lname";
SqlDataSource1.SelectParameters.Add(cookieParam);
}
}
}
Partial Class cookieparam2vb_aspx
Inherits System.Web.UI.Page
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' These cookies might be added by a login form.
' They are added here for simplicity.
If (Not IsPostBack) Then
Dim cookie As HttpCookie
cookie = New HttpCookie("lname", "davolio")
Response.Cookies.Add(cookie)
cookie = New HttpCookie("loginname", "ndavolio")
Response.Cookies.Add(cookie)
cookie = New HttpCookie("lastvisit", DateTime.Now.ToString())
Response.Cookies.Add(cookie)
' You can add a CookieParameter to the SqlDataSource control's
' SelectParameters collection programmatically.
Dim cookieParam As New CookieParameter()
cookieParam.Name = "lastname"
cookieParam.Type = TypeCode.String
cookieParam.CookieName = "lname"
SqlDataSource1.SelectParameters.Add(cookieParam)
End If
End Sub
End Class
Remarks
A CookieParameter object created with the CookieParameter constructor is initialized with default values for all its properties. The CookieName property is initialized to String.Empty. Additionally, the Name property is initialized to String.Empty, the Type property is initialized to TypeCode.Object, the Direction property is initialized to Input, and the DefaultValue property is initialized to null
.
Applies to
CookieParameter(CookieParameter)
Initializes a new instance of the CookieParameter class with the values of the instance specified by the original
parameter.
protected:
CookieParameter(System::Web::UI::WebControls::CookieParameter ^ original);
protected CookieParameter (System.Web.UI.WebControls.CookieParameter original);
new System.Web.UI.WebControls.CookieParameter : System.Web.UI.WebControls.CookieParameter -> System.Web.UI.WebControls.CookieParameter
Protected Sub New (original As CookieParameter)
Parameters
- original
- CookieParameter
A CookieParameter from which the current instance is initialized.
Remarks
The CookieParameter constructor is a protected
copy constructor used to clone a CookieParameter instance. The property values of the CookieParameter object, including CookieName, Name, and Type, are all transferred to the new instance.
See also
Applies to
CookieParameter(String, String)
Initializes a new named instance of the CookieParameter class, using the specified string to identify which HTTP cookie to bind to.
public:
CookieParameter(System::String ^ name, System::String ^ cookieName);
public CookieParameter (string name, string cookieName);
new System.Web.UI.WebControls.CookieParameter : string * string -> System.Web.UI.WebControls.CookieParameter
Public Sub New (name As String, cookieName As String)
Parameters
- name
- String
The name of the parameter.
- cookieName
- String
The name of the HTTP cookie that the parameter object is bound to. The default is Empty.
Examples
The following code example demonstrates how to create a CookieParameter object using the CookieParameter constructor, and add it to a SqlDataSource control's SelectParameters collection.
// You can programmatically add a CookieParameter to the
// SqlDataSource control's SelectParameters collection.
CookieParameter cookieParam = new CookieParameter("lastname","lname");
SqlDataSource1.SelectParameters.Add(cookieParam);
' You can programmatically add a CookieParameter to the
' SqlDataSource control's SelectParameters collection.
Dim cookieParam As New CookieParameter("lastname","lname")
SqlDataSource1.SelectParameters.Add(cookieParam)
Remarks
A CookieParameter object created with the CookieParameter constructor is initialized with the specified parameter name and string that identifies the cookie that the parameter binds to. Other properties, including Type and Direction, are initialized with default values.
See also
Applies to
CookieParameter(String, DbType, String)
Initializes a new instance of the CookieParameter class that has the specified name and database type and that is bound to the specified HTTP cookie.
public:
CookieParameter(System::String ^ name, System::Data::DbType dbType, System::String ^ cookieName);
public CookieParameter (string name, System.Data.DbType dbType, string cookieName);
new System.Web.UI.WebControls.CookieParameter : string * System.Data.DbType * string -> System.Web.UI.WebControls.CookieParameter
Public Sub New (name As String, dbType As DbType, cookieName As String)
Parameters
- name
- String
The name of the parameter.
- dbType
- DbType
The database type that the parameter represents.
- cookieName
- String
The name of the HTTP cookie that the parameter object is bound to. The default is Empty.
See also
Applies to
CookieParameter(String, TypeCode, String)
Initializes a new named and strongly typed instance of the CookieParameter class, using the specified string to identify which HTTP cookie to bind to.
public:
CookieParameter(System::String ^ name, TypeCode type, System::String ^ cookieName);
public CookieParameter (string name, TypeCode type, string cookieName);
new System.Web.UI.WebControls.CookieParameter : string * TypeCode * string -> System.Web.UI.WebControls.CookieParameter
Public Sub New (name As String, type As TypeCode, cookieName As String)
Parameters
- name
- String
The name of the parameter.
- cookieName
- String
The name of the HTTP cookie that the parameter object is bound to. The default is Empty.
Examples
The following code example demonstrates how to create a CookieParameter object using the CookieParameter constructor, and add it to a SqlDataSource control's SelectParameters collection.
// You can programmatically add a CookieParameter to the
// SqlDataSource control's SelectParameters collection.
CookieParameter cookieParam = new CookieParameter("lastname",TypeCode.String,"lname");
SqlDataSource1.SelectParameters.Add(cookieParam);
' You can programmatically add a CookieParameter to the
' SqlDataSource control's SelectParameters collection.
Dim cookieParam As New CookieParameter("lastname",TypeCode.String,"lname")
SqlDataSource1.SelectParameters.Add(cookieParam)
Remarks
A CookieParameter object created with the CookieParameter constructor is initialized with the specified parameter name, Type, and string that identifies the cookie that the parameter binds to. Only the Direction and ConvertEmptyStringToNull properties are initialized with default values.