Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Write cookies using Response Object in code behind asp.net.

Author: Zunnair
Download Source Code : 884_Write Cookies.zip

In this simple article you will learn to write cookies.

 Create a web application in c#

Drag a button, one label and one textbox on the form

Then write code on form load event

 

C#

protected void Page_Load(object sender, EventArgs e)

    {

        Label1.Text = "Cookie Value";

        Button1.Text = "Write Cookie";

    }

VB

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        Label1.Text = "Cookie Value"

        Button1.Text = "Write Cookie"

    End Sub

After that write some code on button click even

C#

protected void Button1_Click(object sender, EventArgs e)

protected void Button1_Click(object sender, EventArgs e)

    {

        System.Web.HttpCookie cookie = new HttpCookie("CookieTest");

        cookie.Value = TextBox1.Text.Trim();

        cookie.Expires = DateTime.Now.AddDays(1);

        Response.Cookies.Add(cookie);

    }

VB

  Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim cookie As System.Web.HttpCookie = New HttpCookie("CookieTest")

        cookie.Value = TextBox1.Text.Trim()

        cookie.Expires = DateTime.Now.AddDays(1)

        Response.Cookies.Add(cookie)

    End Sub

 

This is simple code to write cookies using Response object.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Read cookies using Response Object in code behind asp.net.

Disclaimer - Privacy
© 2002-2017 DevASP.net