473,396 Members | 1,703 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.

Code called twice

Hello,

I have a listbox control, which has multiple selection
enabled. Now, I need to retrieve all selected items when
the submit button is clicked. It works very well, but the
only problem is that it returns the data 2 times. I mean
it returns duplicated data. Lets say I selected one item,
and press the submit button. When I do a response.write
then I can see the item two times. Why is that happening?
My code:

Private Sub btnTest_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnTest.Click
Dim i As Integer
Dim str As String
For i = 0 To listStores.Items.Count - 1

If listStores.Items(i).Selected Then
str &= listStores.Items(i).Text
str &= str & ","
End If
Next

' strip of the last comma, which is always the
last position in the string
str = str.Substring(0, str.Length() - 1)

Response.Write(str)
Nov 19 '05 #1
2 983
Check out this faq,
http://www.extremeexperts.com/Net/FA...ringTwice.aspx

--
-Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com

"anonymous" <an*******@discussions.microsoft.com> wrote in message
news:25****************************@phx.gbl...
Hello,

I have a listbox control, which has multiple selection
enabled. Now, I need to retrieve all selected items when
the submit button is clicked. It works very well, but the
only problem is that it returns the data 2 times. I mean
it returns duplicated data. Lets say I selected one item,
and press the submit button. When I do a response.write
then I can see the item two times. Why is that happening?
My code:

Private Sub btnTest_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnTest.Click
Dim i As Integer
Dim str As String
For i = 0 To listStores.Items.Count - 1

If listStores.Items(i).Selected Then
str &= listStores.Items(i).Text
str &= str & ","
End If
Next

' strip of the last comma, which is always the
last position in the string
str = str.Substring(0, str.Length() - 1)

Response.Write(str)

Nov 19 '05 #2
Make sure that the autoeventwirup property of the page is set to False

"anonymous" wrote:
Hello,

I have a listbox control, which has multiple selection
enabled. Now, I need to retrieve all selected items when
the submit button is clicked. It works very well, but the
only problem is that it returns the data 2 times. I mean
it returns duplicated data. Lets say I selected one item,
and press the submit button. When I do a response.write
then I can see the item two times. Why is that happening?
My code:

Private Sub btnTest_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnTest.Click
Dim i As Integer
Dim str As String
For i = 0 To listStores.Items.Count - 1

If listStores.Items(i).Selected Then
str &= listStores.Items(i).Text
str &= str & ","
End If
Next

' strip of the last comma, which is always the
last position in the string
str = str.Substring(0, str.Length() - 1)

Response.Write(str)

Nov 19 '05 #3

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

Similar topics

3
by: Alexander Stippler | last post by:
Given the following code snippet we get some unexpected behaviour: //-------------------------------------------------------------------- #include <iostream> using namespace std; struct A {...
8
by: Andy | last post by:
Visual Studio 2003 web form problem using C#. My Page_Load or OnInit routines seems to be called twice for every post back to the server. I have 2 web forms that produce this behaviour, all of...
6
by: Dot net work | last post by:
I've read quite a few threads on these groups about this. When someone says the following: "My Page_Load gets called twice on a button click postback" The replies are: "Do you have...
1
by: Vishal | last post by:
Hello, I have a datagrid, which calculates the total in the footer. I am using public variables and simply appending the data to it. However the footertemplate is called twice and therefore it...
3
by: Imran Aziz | last post by:
Hello All, I have a search text and button that post data and my button handler filters the repeater control. However when the button is clicked the first time. The page_load event is being called...
5
by: dbuchanan | last post by:
Hello, I can find no reason for this code to run twice. Can you help me? It may have something to do with it being a overrides sub but stepping through during debug does *not* bear this out. ...
2
by: Kevin Sun | last post by:
I have a problem about non-managed code and managed code.Could you like to give me some suggestion? In a non-managed MFC application project, I add some managed codes and these files are setted...
11
by: Rimpinths | last post by:
I'm new at developing user controls in C#, and one thing I've noticed right off the bat is that the constructor gets called twice -- once at design time, once at run time. In short, I'm trying...
6
by: =?Utf-8?B?TWF0dA==?= | last post by:
I'm having a problem with a static class constructor being called twice. I have the static class MasterTaskList which uses a BackgroundWorker to execute multiple methods on a separate thread. The...
2
by: Anil Gupte/iCinema.com | last post by:
I am getting the following message and no, it is not even going to that statement twice. Why is this happening? System.NotSupportedException was caught Message="FlushFinalBlock() method was...
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
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...
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
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...
0
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,...

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.