Hi,
Please refer below code.
C#
// To Set Into Cookies
NameValueCollection collection = new NameValueCollection();
collection.Add("FirstName", FirstNameTextBox.Text);
collection.Add("LastName", LastNameTextBox.Text);
collection.Add("Mobile", MobileTextBox.Text);
collection.Add("Tell", TellTextBox.Text);
collection.Add("Address", AddressTextBox.Text);
HttpCookie cookie = new HttpCookie("UserData");
cookie.Values.Add(collection);
Response.Cookies.Add(cookie);
// To Get from Cookies
if (Request.Cookies["UserData"] != null)
{
NameValueCollection datacollection = Request.Cookies["UserData"].Values;
string firstName = datacollection["FirstName"];
string lastName = datacollection["LastName"];
}
VB
Dim collection As New NameValueCollection()
collection.Add("FirstName", FirstNameTextBox.Text)
collection.Add("LastName", LastNameTextBox.Text)
collection.Add("Mobile", MobileTextBox.Text)
collection.Add("Tell", TellTextBox.Text)
collection.Add("Address", AddressTextBox.Text)
Dim cookie As New HttpCookie("UserData")
cookie.Values.Add(collection)
Response.Cookies.Add(cookie)
' To Get from Cookies
If Request.Cookies("UserData") IsNot Nothing Then
Dim datacollection As NameValueCollection = Request.Cookies("UserData").Values
Dim firstName As String = datacollection("FirstName")
Dim lastName As String = datacollection("LastName")
End If
UserData
C#
public class UserData
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Mobile { get; set; }
public string Tell { get; set; }
public string Address { get; set; }
}
VB
Public Class UserData
Public Property FirstName() As String
Get
Return m_FirstName
End Get
Set
m_FirstName = Value
End Set
End Property
Private m_FirstName As String
Public Property LastName() As String
Get
Return m_LastName
End Get
Set
m_LastName = Value
End Set
End Property
Private m_LastName As String
Public Property Mobile() As String
Get
Return m_Mobile
End Get
Set
m_Mobile = Value
End Set
End Property
Private m_Mobile As String
Public Property Tell() As String
Get
Return m_Tell
End Get
Set
m_Tell = Value
End Set
End Property
Private m_Tell As String
Public Property Address() As String
Get
Return m_Address
End Get
Set
m_Address = Value
End Set
End Property
Private m_Address As String
End Class
I hope this will help you out.