Cookies and Events Problems

Discussion in 'ASP .Net' started by =?Utf-8?B?bHR0MTk=?=, Dec 19, 2004.

  1. Hi Folks,

    I'm just beggining with asp.net, and I'm doing a webpage to learn it. In the
    main page, there is a text by default written in Portuguese, that the user
    can change it it English by clicking on a button. When you click in this
    button it writes a cookie with your chosen language, and then the page loads
    again to change the text. However I'm having two problems, first, the cookie
    doens't work, second, to fix the cookie problem, i marked each line of the
    below code with a breakpoint, then I noticed that when i click in the button
    the Page.Load event is raised then the Button.Click if raises after.. Why
    this? Is it really supposed to happen? I'm more preocupated with the second
    problem cause i'm used to windows appications and I was not expecting that
    this could happen.
    This is the code:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    Dim lang As String 'p means portuguese, e means english.
    If Response.Cookies("Site")("Lang") = "english" Then
    lang = "infoe.txt"
    btnSwitch.Text = "Portugues"
    Else
    lang = "infop.txt"
    btnSwitch.Text = "English"
    End If
    Dim ir As New IO.StreamReader(Server.MapPath("./Data/" & lang), enc)
    lblInfo.Text = ir.ReadToEnd
    ir.Close()
    End Sub

    Private Sub btnSwitch_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles btnSwitch.Click
    Dim langc As String = Request.Cookies("Site")("Lang")
    If langc = "portugues" Or langc = String.Empty Then
    Request.Cookies("Site")("Lang") = "english"
    Request.Cookies("Site").Expires = Now.AddMonths(1)
    Else
    Request.Cookies("Site")("Lang") = "portugues"
    Request.Cookies("Sitet").Expires = Now.AddMonths(1)
    End If
    End Sub

    Any help would be VERY apprecciated.
    Thanks in advance.
    ltt19
     
    =?Utf-8?B?bHR0MTk=?=, Dec 19, 2004
    #1
    1. Advertising

  2. "ltt19" <> wrote in message
    news:...
    > Hi Folks,
    >
    > I'm just beggining with asp.net, and I'm doing a webpage to learn it. In
    > the
    > main page, there is a text by default written in Portuguese, that the user
    > can change it it English by clicking on a button. When you click in this
    > button it writes a cookie with your chosen language, and then the page
    > loads
    > again to change the text. However I'm having two problems, first, the
    > cookie
    > doens't work, second, to fix the cookie problem, i marked each line of the
    > below code with a breakpoint, then I noticed that when i click in the
    > button
    > the Page.Load event is raised then the Button.Click if raises after.. Why
    > this? Is it really supposed to happen? I'm more preocupated with the
    > second
    > problem cause i'm used to windows appications and I was not expecting that
    > this could happen.


    Yes, Page_Load is meant to be raised before Click events. Take a look at
    The ASP.NET Page Object Model
    (http://msdn.microsoft.com/library/d...p/html/aspnet-pageobjectmodel.asp?frame=true).



    John Saunders
     
    John Saunders, Dec 19, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Nitulescu

    Response.Cookies vs Request.Cookies

    Alex Nitulescu, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,491
    Hans Kesting
    Feb 3, 2005
  2. Andy Fish
    Replies:
    3
    Views:
    6,534
    Fredrik Lindner
    Nov 6, 2003
  3. archana
    Replies:
    1
    Views:
    507
  4. _Who
    Replies:
    7
    Views:
    2,674
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    366
    Chris
    Aug 30, 2005
Loading...

Share This Page