473,395 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Cookies and Events Problems

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
Nov 19 '05 #1
1 1047
"ltt19" <lt***@discussions.microsoft.com> wrote in message
news:91**********************************@microsof t.com...
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


Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Phil Powell | last post by:
Ok now it has turned to the bizarre. In /cma/index.php, which sets the cookie: setcookie('username', $username, time() + 600); .... header("Location..."); It redirects to the TCL CGI...
0
by: yukon | last post by:
Hi there the next is my platform IIS5 windows 2000 asp vbscript My working area has the next virtual directoy: testAc (corrective ambient) testAe (evolutionary ambient)
0
by: Dan Meehan | last post by:
I created a music website that allows people to sign up and post messages on some message boards and update their profiles and such. The login script uses cookies, so when they Log Into the site it...
2
by: Amit D.Shinde | last post by:
Hello Experts.. I need some help regarding cookies and session objects and also global.asa file I am creating one cookie when a user logs in on my website. The cookie stores the login name of...
9
by: | last post by:
Is it possible for a user to enable permanent cookies but disable session cookies.....this seems like a contradition yet this is what I appear to be reading in online articles?
6
by: Mark | last post by:
Hi... I've come across some weird bug with Response.Cookies. Or maybe it will be called "by design" but for the life of me I can't figure out what purpose it would serve. If you're setting a...
3
by: Nicolae Fieraru | last post by:
Hi All, I have a lot of problems with the web site www.ggsurf.com.au I host on www.gnxonline.com and I want to find out if it is my own problem or theirs. I try to use session cookies and it...
4
by: BobRoyAce | last post by:
I have a C# ASP.NET page that I inherited which has two panels on it. It only ever shows one or the other. Initially, it shows panel one. Then, if the user clicks on a certain button, it ultimately...
5
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.