Friday, August 28, 2015

ASP.NET VB.NET Tutorials - State Management using Cookies In Urdu


The Code is below ...
Code behind for "Default.aspx.vb"
Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim httpCookie As HttpCookie = Request.Cookies("Name")

        If httpCookie Is Nothing Then
            txtDiv.Visible = True
        Else
            msgDiv.Visible = True
            WelcomeLabel.Text = "Welcome back - " & httpCookie.Values("ClientName")
        End If

    End Sub

    Protected Sub SignUpButton_Click(sender As Object, e As EventArgs) Handles SignUpButton.Click

        Dim httpCookie As New HttpCookie("Name")
        httpCookie.Values.Add("ClientName", NameTextBox.Text)
        httpCookie.Expires = DateTime.Now.AddDays(1)

        Response.Cookies.Add(httpCookie)

        Response.Redirect("Thanks.aspx?name=" & NameTextBox.Text)

    End Sub
End Class

Code behind for "Thanks.aspx.vb"
Public Class Thanks
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        NameLabel.Text = Request.QueryString("name")
    End Sub

End Class

No comments:

Post a Comment