Wrox Programmer Forums
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 5th, 2006, 06:34 AM
Authorized User
Join Date: Apr 2006
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default session updates too slow

Hi again,

I have a puzzling experience with a flag (English/Swedish) that I use for letting the user choose language of the web site. For some reason the page does refresh but the language settings aren't updated the first time the flag is clicked, but after that, it's updated every time. I guessed it had to do with EnableViewState or so, but I can't spot the error. Please help me out if you spot this silly error that's driving me crazy.

The sub for changing the session (and cookie too):

Protected Sub FlaggaImageButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles FlaggaImageButton.Click
        If FlaggaImageButton.ImageUrl = "img/unionjack.gif" Then Session("lang") = "en"
        If FlaggaImageButton.ImageUrl = "img/gulbla.gif" Then Session("lang") = "sv"
        Dim c As New System.Web.HttpCookie("langcookie", Session("lang"))
        c.Expires = Now.AddDays(10000)
    End Sub

The ImageButton itself:
<asp:ImageButton ID="FlaggaImageButton" runat="server" Style="z-index: 108; left: 830px; top: 120px; position: absolute;" />

The PageLoad's first lines:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Request.Cookies("langcookie") Is Nothing Then Session("lang") = Request.Cookies("langcookie").Value
        If Request.Cookies("langcookie") Is Nothing And Session("lang") Is Nothing Then Session("lang") = "sv"

        If Session("lang") = "sv" Then
            TaglineImage.ImageUrl = "img/tagline_sv.gif"
            HemsokLabel.Text = "<a href=""Default.aspx"">Hem/Sök</a>"
            HemsokLabel.ToolTip = "Till startsidan/Sök i katalogen"

Thanks in advance!


Coding is indeed a nine-to-five job; nine pm to five am.
Coding is indeed a nine-to-five job; nine pm to five am.
Old June 5th, 2006, 12:12 PM
Friend of Wrox
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts

You are creating the cookie each time in the click event. You should check if the cookie exists in the page_load event, if it does'nt then create it. In the click event, just set the cookied, don't recreate it.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parameter Updates HelmutArnold Reporting Services 3 October 23rd, 2006 09:06 AM
Updates? GeekyMonkey BOOK: Professional Web Parts and Custom Controls ASP.NET ISBN: 0-7645-7860-X 12 May 24th, 2006 12:11 PM
What happens if someone else updates the data jaideepc ADO.NET 2 August 11th, 2004 12:02 PM
Transactional UPDATEs djm2cmu BOOK: ASP.NET Website Programming Problem-Design-Solution 0 January 20th, 2004 11:42 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.