473,804 Members | 3,251 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add to Array in Session with checkbox handler

gce
What happens :

When I first press the button, I get an listbox1 with a,b,c (correct:
because of the
addtoa(1, "a")
addtoa(2, "b")
addtoa(3, "c")

When I check the checkbox, the eventhandler triggers and when I press the
button, the addtoa(4,"d") works fine, because I have a listbox with a,b,c,d

But now the strange thing. When I press the button again, the d is lost
again. This is just a testcode, but in my program I have the same problem
with adding something to an array inside a handler using the session var.

Please help me !
Public Class frmArrayTest1
Inherits System.Web.UI.P age

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents ListBox1 As System.Web.UI.W ebControls.List Box
Protected WithEvents CheckBox1 As System.Web.UI.W ebControls.Chec kBox
Protected WithEvents Button1 As System.Web.UI.W ebControls.Butt on

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here

Dim a
ReDim Preserve a(4, 4)

AddHandler CheckBox1.Check edChanged, AddressOf
CheckBox1_Check edChanged

Session("test") = a
addtoa(1, "a")
addtoa(2, "b")
addtoa(3, "c")

End Sub

Private Sub addtoa(ByVal intIndex, ByVal strString)

Dim a

'ListBox1.Items .Add(strString)

a = Session("test")
a(intIndex, 2) = strString
Session("test") = a
End Sub

Private Sub CheckBox1_Check edChanged(ByVal sender As Object, ByVal e As
System.EventArg s) Handles CheckBox1.Check edChanged
addtoa(4, "d")

End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim x
Dim i

x = Session("test")
ListBox1.Items. Clear()
For i = 1 To UBound(x)
ListBox1.Items. Add(Str(i) & "-" & x(i, 2))
Next i
End Sub
End Class
Nov 19 '05 #1
2 1774
Hi!

I'm no VB guru (love C# ;) ), but I have a feeling you might get a little
bit more predictable code if you don't re-initialize the array in Page_Load
each time. There's a property on Page called IsPostBack which is true if the
request is a postback (i.e. the user clicked a control)

Try modifying your Page_Load code like this so that the array isn't
initialized when the user clicks the button:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
Dim a
ReDim Preserve a(4, 4)

Session("test") = a
addtoa(1, "a")
addtoa(2, "b")
addtoa(3, "c")

End Sub
"gce" <gc****@hotmail .com> wrote in message
news:d4******** **@news5.zwoll1 .ov.home.nl...
What happens :

When I first press the button, I get an listbox1 with a,b,c (correct:
because of the
addtoa(1, "a")
addtoa(2, "b")
addtoa(3, "c")

When I check the checkbox, the eventhandler triggers and when I press the
button, the addtoa(4,"d") works fine, because I have a listbox with
a,b,c,d

But now the strange thing. When I press the button again, the d is lost
again. This is just a testcode, but in my program I have the same problem
with adding something to an array inside a handler using the session var.

Please help me !
Public Class frmArrayTest1
Inherits System.Web.UI.P age

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents ListBox1 As System.Web.UI.W ebControls.List Box
Protected WithEvents CheckBox1 As System.Web.UI.W ebControls.Chec kBox
Protected WithEvents Button1 As System.Web.UI.W ebControls.Butt on

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here

Dim a
ReDim Preserve a(4, 4)

AddHandler CheckBox1.Check edChanged, AddressOf
CheckBox1_Check edChanged

Session("test") = a
addtoa(1, "a")
addtoa(2, "b")
addtoa(3, "c")

End Sub

Private Sub addtoa(ByVal intIndex, ByVal strString)

Dim a

'ListBox1.Items .Add(strString)

a = Session("test")
a(intIndex, 2) = strString
Session("test") = a
End Sub

Private Sub CheckBox1_Check edChanged(ByVal sender As Object, ByVal e As
System.EventArg s) Handles CheckBox1.Check edChanged
addtoa(4, "d")

End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim x
Dim i

x = Session("test")
ListBox1.Items. Clear()
For i = 1 To UBound(x)
ListBox1.Items. Add(Str(i) & "-" & x(i, 2))
Next i
End Sub
End Class

Nov 19 '05 #2
Sorry, keyboard catched a non-intended ctrl+enter ;)
Here's the code I was proposing:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here

AddHandler CheckBox1.Check edChanged, AddressOf
CheckBox1_Check edChanged

' Without If Not IsPostBack, array is rebuilt on each roundtrip, and
your previous data is lost
If Not IsPostBack Then
Dim a
ReDim Preserve a(4, 4)

addtoa(1, "a")
addtoa(2, "b")
addtoa(3, "c")
Session("test") = a
End If

End Sub

"gce" <gc****@hotmail .com> wrote in message
news:d4******** **@news5.zwoll1 .ov.home.nl...
What happens :

When I first press the button, I get an listbox1 with a,b,c (correct:
because of the
addtoa(1, "a")
addtoa(2, "b")
addtoa(3, "c")

When I check the checkbox, the eventhandler triggers and when I press the
button, the addtoa(4,"d") works fine, because I have a listbox with
a,b,c,d

But now the strange thing. When I press the button again, the d is lost
again. This is just a testcode, but in my program I have the same problem
with adding something to an array inside a handler using the session var.

Please help me !
Public Class frmArrayTest1
Inherits System.Web.UI.P age

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents ListBox1 As System.Web.UI.W ebControls.List Box
Protected WithEvents CheckBox1 As System.Web.UI.W ebControls.Chec kBox
Protected WithEvents Button1 As System.Web.UI.W ebControls.Butt on

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here

Dim a
ReDim Preserve a(4, 4)

AddHandler CheckBox1.Check edChanged, AddressOf
CheckBox1_Check edChanged

Session("test") = a
addtoa(1, "a")
addtoa(2, "b")
addtoa(3, "c")

End Sub

Private Sub addtoa(ByVal intIndex, ByVal strString)

Dim a

'ListBox1.Items .Add(strString)

a = Session("test")
a(intIndex, 2) = strString
Session("test") = a
End Sub

Private Sub CheckBox1_Check edChanged(ByVal sender As Object, ByVal e As
System.EventArg s) Handles CheckBox1.Check edChanged
addtoa(4, "d")

End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim x
Dim i

x = Session("test")
ListBox1.Items. Clear()
For i = 1 To UBound(x)
ListBox1.Items. Add(Str(i) & "-" & x(i, 2))
Next i
End Sub
End Class

Nov 19 '05 #3

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

Similar topics

6
2394
by: Al Jones | last post by:
This is a repost form the vbscript newgroup - if this isn't the appropriate group would you point me toward one that is. Basically, I seem to be losing session data part way though preparing an email from (possibly) three seperate forms. the following code is the end of a routine which stashes data from the first form off to session variables and then redirects itself to the proper form / procedure depending upon the state of two...
13
31486
by: aundro | last post by:
Hello, I've been looking on the web for a solution to this problem: I create a set of checkboxes, and 2 buttons: - one is labeled "All" - the other is labeled "None" Clicking "All" is supposed to check all the checkboxes, which it does (that's not rocket science ;), but the 'onchange' event does not get triggered.
0
2322
by: http://www.visual-basic-data-mining.net/forum | last post by:
I am using a checkbox as follows: protected System.Web.UI.WebControls.CheckBoxList cblReading; Now I store the index(checked marked) in an array for postback method, i.e., I save the selected indexes in array : ArrayList selItems = (ArrayList)Session; And I have to repopulate the cblReading on post back. DataView for ReadingsList // property delivers the list of Reading
7
11092
by: Oleg Konovalov | last post by:
Hi, I am trying to pass a bunch of checked checkboxes (Javascript array) from page1 to the Java action class on subsequent web page (page2). (on page 1 I have a bunch of DB rows with a checkbox, need to iterate through pages page2 - e.g. allow user to update the fields there) On page1 I have a bunch of checkboxes with the same name v1 but different values (= DB rowId).
9
2096
by: Rainman | last post by:
In my HTML, I have several of the following: <input type='checkbox' name='right' id='right' value='0' /> All are the same except the value is set differently for each one. The reason for the is so I can access the checkbox values as an array on the processing page (when clicking 'Submit'); However, I want my Javascript code to examine these objects first. My onclick event handler function (below) is called (I get the 'hi there'
14
2384
by: aroraamit81 | last post by:
Hi, I am facing a trouble. I have some Session variables in my code and somehow my session variables are getting mixed up with other users. For example User A has access to 10 companies and User B has access to 5, now when both of us hits to the server at the same time then their session variables gets mixedup means either User A and USer B will have now 5 companies or both have 10 companies. Now again when User A hits to the server...
4
157580
by: _Mario.lat | last post by:
Hallo, I have a little question: In the function session_set_save_handler I can pass the name of function which deal with session. In Xoops code I see the use of this function like that: session_set_save_handler(array(&$sess_handler, 'open'), array(&$sess_handler, 'close'), array(&$sess_handler, 'read'), array(&$sess_handler, 'write'), array(&$sess_handler, 'destroy'), array(&$sess_handler, 'gc'));
4
4441
by: Charlotte | last post by:
Hi, I have a problem with a ASP-script, can somewone help me ? here is what I've got: mypage.asp : .... code ... <%
4
1652
by: sjohnson1984 | last post by:
Hello all, I have a form which is generated using a database query - the recordset is filled with agent details, login time and the like, and there are as many rows in the table as records in the set (plus table header). My problem is that I do not know how to pass the details of each record to an array session variable, once the form is submitted, and subsequently write all of this info to a dB. I have no problem doing this when there...
0
9587
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10324
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3827
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.