473,396 Members | 2,108 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,396 software developers and data experts.

Problem with session variables in Page_Load

I have a simple application that has a map. The user has to select two
sets from a single type of feature from the map. I use two radio
buttons under same GroupName for each set.

When the page loads for the first time, one radio button is checked
(obviously the other is unchecked). The user selects for one set and
checks the other radio button. Since, I have the AutoPostBack to be
true, the page loads again and the radio button for the second set is
checked. The state of the radio buttons is stored in session variables.

Everything is fine till now. Now starts the problem and struggle (!!).
With the second radio button checked, when I select any feature to add
to the second set, the selected features get added to the first set and
the radio button for the first set is checked and that for the second
set is unchecked on its own. I observed that this happens in the
Page_Load method only (Please refer to the code below). In other
methods the session variables are as intended

I have been struggling with this problem from many days. Can someone
please help ? Thank you very much

The code is the following:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim sMode As String
Dim iMode As Integer = 0

If Not Page.IsPostBack Then
RB1.Checked = Session("Checked1")
RB2.Checked = Session("Checked2")
Me.sUrl = CreateStreetMap(1)
End If

End Sub

Public Function CreateStreetMap(ByVal AMode As Integer) As String
....
....
....
Dim s1 As String
Dim s2 As String

If (RB1.Checked = True) Then
s1 = Request.QueryString("fieldname")
If Not s1 = "" Then
Session("Collection1") = _
Session("Collection1") & "," & s1
End If
End If

If (RB2.Checked = True) Then
s2 = Request.QueryString("fieldname")
If Not s2 = "" Then
Session("Collection2") = _
Session("Collection2") & "," & s2
End If
End If
TextBox1.Text = Session("Collection1")
TextBox2.Text = Session("Collection2")
....
....
....
End Function

Private Sub RB1_CheckedChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles IncidentLinkRB.CheckedChanged
Session("Checked1") = RB1.Checked
Session("Checked2") = Not (RB2.Checked)
Session("checkChanged") = True

Me.sUrl = CreateStreetMap(1)

End Sub

Private Sub RB2_CheckedChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetourLinkRB.CheckedChanged
Session("Checked1") = Not (RB2.Checked)
Session("Checked2") = RB2.Checked
Session("checkChanged") = True

Me.sUrl = CreateStreetMap(1)

End Sub

Mar 7 '06 #1
3 4170
In RB2_CheckedChanged you have Session("Checked1") being set to
Not(RB2.Checked). Shouldn't that be Not(RB1.Checked)?

HTH,
Darren Kopp
http://blog.secudocs.com/

Mar 7 '06 #2
Hi Darren,
I tried both:
Session("Checked1") = Not (RB1.Checked)
and Session("Checked1") = RB1.Checked
and likewise in RB1_CheckChanged. The result is the same.

Sandeep

Mar 7 '06 #3
I would recommend using the RadioButtonList class if you can only
select one radiobutton at a time, then just figure out which one is
selected using the SelectedItem property, then bind based on that
logic. If you can simultaneously select both, then use a CheckBox
control. If that's not possible, then I would make a few corrections
to your code as such.

in the page load section, i would use this code

' --------------------------------------
If Not Page.IsPostBack Then
RB1.Checked = CType(Session("Checked1"), Boolean)
RB2.Checked = CType(Session("Checked2"), Boolean)
Me.sUrl = CreateStreetMap(1)
End If
' --------------------------------------

I would also modify the following OnCheckedEvents

' --------------------------------------
Private Sub RB1_CheckedChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles IncidentLinkRB.CheckedChanged
Session("Checked1") = RB1.Checked
' Session("Checked2") = Not (RB2.Checked) - commented out, session
should already have this value? if not, initialize Session with
default values
Session("checkChanged") = True
Me.sUrl = CreateStreetMap(1)
End Sub
Private Sub RB2_CheckedChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetourLinkRB.CheckedChanged
' Session("Checked1") = Not (RB2.Checked) - commented out - session
should already have this value, if not, initialize session with default
values earlier
Session("Checked2") = RB2.Checked
Session("checkChanged") = True
Me.sUrl = CreateStreetMap(1)
End Sub
' ---------------------------------------------------------

When i say initialize earlier, i mean something in the If Not
Page.IsPostBack adding something like this

'------------------------------------------------------------
If Session("Checked1") = Nothing Then
Session("Checked1") = false
End If

If Session("Checked2") = Nothing Then
Session("Checked2") = false
End If

'------------------------------------------------

That way, you won't accidently overwrite your values if that is what
may be happening.

Let me know if you are still having problems. If needed, you can email
me the full code at darrenkopp [at] [gmail dot com] and I will look
through it more in depth.

-Darren Kopp
http://blog.secudocs.com/

Mar 7 '06 #4

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

Similar topics

8
by: Ashish | last post by:
Incase the problem got bogged down reposting... Hi Gregory, I think I didnt make myself much clear. The problem is: 1. I have one ASP.NET application (no classic asp) and it has a main page...
1
by: DavidS | last post by:
I'm losing session state variables during my debug session. Basically, I've expanded on web development - worked with web site for about 4 months now without problems. I'm adding code to web pages...
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
0
by: Alexander Widera | last post by:
hello all, i have a problem ... like I already discussed in the thread "session empty" I have the following problem: I created a completely new web... i added 2 files: sessiontest1.aspx:
1
by: Steve Wark | last post by:
If I create two aspx pages, place three text boxes (working with VS .net 2003 and web form controls) and a button on both forms. On the first page, the button is set to use the "onClick" to open...
1
by: daniel_xi | last post by:
Hi all, I am running a VS 2003 .NET project on my client machine (Win 2000 SP4, ..NET framework 1.1), running an ASP.NET application on a remote web server (Win 2000 Server, IIS 6.0, .NET...
2
by: ronchese | last post by:
I'm noticing this since I started developing a website project: my session variables are getting empty! I did a real easy test, and I checked my session variable is getting empty!! What is...
3
by: danyadler | last post by:
Hi All, The old topic: Session variables desappear. I cannot understand it! And it's driving me crazy!! So most of my aspx pages works just fine, but only 2 pages decide that after they are...
0
by: bharathreddy | last post by:
Here I will given an example on how to access the session, application and querystring variables in an .cs class file. Using System.Web.HttpContext class. 1) For accesing session variables :...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.