Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Cookies and Events Problems

Reply
Thread Tools

Cookies and Events Problems

 
 
=?Utf-8?B?bHR0MTk=?=
Guest
Posts: n/a
 
      12-19-2004
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
 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      12-19-2004
"ltt19" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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/de...sp?frame=true).



John Saunders




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Give Request.Cookies and Response.Cookies is there any reason to use another method to use cookies? _Who ASP .Net 7 09-18-2008 07:49 PM
Persistant cookies and non-persistant cookies. archana ASP .Net 1 05-25-2007 08:43 AM
Events Events Events Please Help Chris ASP .Net Web Controls 0 08-30-2005 08:21 PM
Response.Cookies vs Request.Cookies Alex Nitulescu ASP .Net 1 02-03-2005 09:43 AM
Persistent Cookies vs. session cookies Andy Fish Java 3 11-06-2003 10:44 AM



Advertisments