473,670 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OnSelectedIndex Changed runs twice!

Using ASP.NET 2.0...

My GridView is partially defined as such....

<asp:GridView ID="CartGrid" AutoGenerateCol umns="False"
DataKeyNames="I D" OnSelectedIndex Changed="Remove CartItem"
CellPadding="4" runat="Server"
ForeColor="Gray " GridLines="None " Width="90%"
BorderStyle="In set"
BorderWidth="1p x" Caption="Shoppi ng Cart" Font-Bold="False"
CaptionAlign="L eft">
<Columns>
<asp:ButtonFiel d
CommandName="se lect" Text="Remove" />
<asp:BoundFie ld
DataField="Name " HeaderText="Nam e">
<ControlStyle
Width="300px" />
<ItemStyle Width="300px"
/>

As you can see, when the user clicks "Remove" it runs the "RemoveCartItem "
function, defined as such...

Sub RemoveCartItem( ByVal s As Object, ByVal e As EventArgs) Handles
CartGrid.Select edIndexChanged
Dim ID As String = CartGrid.Select edDataKey.Value
Profile.MyShopp ingCart.RemoveI tem(ID)
BindShoppingCar t()
End Sub
Sub BindShoppingCar t()
If Not Profile.MyShopp ingCart Is Nothing Then
CartGrid.DataSo urce = Profile.MyShopp ingCart.CartIte ms
CartGrid.DataBi nd()
lblTotal.Text = Profile.MyShopp ingCart.Total.T oString("c")
BindShippingDdl ()
End If
End Sub

I put a breakpoint on RemoveCartItem and the code is running twice each
time. Any ideas why?

Thanks!
Mar 22 '06 #1
3 1477
FYI: Even AFTER I comment out the BindShoppingCar t call it still calls
RemoveCartItem twice...

Any ideas?

"VB Programmer" <do**@emailme.c om> wrote in message
news:uS******** ******@TK2MSFTN GP11.phx.gbl...
Using ASP.NET 2.0...

My GridView is partially defined as such....

<asp:GridView ID="CartGrid" AutoGenerateCol umns="False"
DataKeyNames="I D" OnSelectedIndex Changed="Remove CartItem"
CellPadding="4" runat="Server"
ForeColor="Gray " GridLines="None " Width="90%"
BorderStyle="In set"
BorderWidth="1p x" Caption="Shoppi ng Cart" Font-Bold="False"
CaptionAlign="L eft">
<Columns>
<asp:ButtonFiel d
CommandName="se lect" Text="Remove" />
<asp:BoundFie ld
DataField="Name " HeaderText="Nam e">
<ControlStyle
Width="300px" />
<ItemStyle
Width="300px" />

As you can see, when the user clicks "Remove" it runs the "RemoveCartItem "
function, defined as such...

Sub RemoveCartItem( ByVal s As Object, ByVal e As EventArgs) Handles
CartGrid.Select edIndexChanged
Dim ID As String = CartGrid.Select edDataKey.Value
Profile.MyShopp ingCart.RemoveI tem(ID)
BindShoppingCar t()
End Sub
Sub BindShoppingCar t()
If Not Profile.MyShopp ingCart Is Nothing Then
CartGrid.DataSo urce = Profile.MyShopp ingCart.CartIte ms
CartGrid.DataBi nd()
lblTotal.Text = Profile.MyShopp ingCart.Total.T oString("c")
BindShippingDdl ()
End If
End Sub

I put a breakpoint on RemoveCartItem and the code is running twice each
time. Any ideas why?

Thanks!

Mar 22 '06 #2
Got it! I removed "Handles CartGrid.Select edIndexChanged" from
RemoveCartItem and it works. It was calling twice, once from the dg and
once from the SelectedIndexCh anged event I suppose.

"VB Programmer" <do**@emailme.c om> wrote in message
news:uf******** ******@TK2MSFTN GP11.phx.gbl...
FYI: Even AFTER I comment out the BindShoppingCar t call it still calls
RemoveCartItem twice...

Any ideas?

"VB Programmer" <do**@emailme.c om> wrote in message
news:uS******** ******@TK2MSFTN GP11.phx.gbl...
Using ASP.NET 2.0...

My GridView is partially defined as such....

<asp:GridView ID="CartGrid" AutoGenerateCol umns="False"
DataKeyNames="I D" OnSelectedIndex Changed="Remove CartItem"
CellPadding="4" runat="Server"
ForeColor="Gray " GridLines="None " Width="90%"
BorderStyle="In set"
BorderWidth="1p x" Caption="Shoppi ng Cart" Font-Bold="False"
CaptionAlign="L eft">
<Columns>
<asp:ButtonFiel d
CommandName="se lect" Text="Remove" />
<asp:BoundFie ld
DataField="Name " HeaderText="Nam e">
<ControlStyle
Width="300px" />
<ItemStyle
Width="300px" />

As you can see, when the user clicks "Remove" it runs the
"RemoveCartItem " function, defined as such...

Sub RemoveCartItem( ByVal s As Object, ByVal e As EventArgs) Handles
CartGrid.Select edIndexChanged
Dim ID As String = CartGrid.Select edDataKey.Value
Profile.MyShopp ingCart.RemoveI tem(ID)
BindShoppingCar t()
End Sub
Sub BindShoppingCar t()
If Not Profile.MyShopp ingCart Is Nothing Then
CartGrid.DataSo urce = Profile.MyShopp ingCart.CartIte ms
CartGrid.DataBi nd()
lblTotal.Text = Profile.MyShopp ingCart.Total.T oString("c")
BindShippingDdl ()
End If
End Sub

I put a breakpoint on RemoveCartItem and the code is running twice each
time. Any ideas why?

Thanks!


Mar 23 '06 #3
hmm Good you noticed that
Patrick

"VB Programmer" <do**@emailme.c om> wrote in message
news:u3******** ******@TK2MSFTN GP11.phx.gbl...
Got it! I removed "Handles CartGrid.Select edIndexChanged" from
RemoveCartItem and it works. It was calling twice, once from the dg and
once from the SelectedIndexCh anged event I suppose.

"VB Programmer" <do**@emailme.c om> wrote in message
news:uf******** ******@TK2MSFTN GP11.phx.gbl...
FYI: Even AFTER I comment out the BindShoppingCar t call it still calls
RemoveCartItem twice...

Any ideas?

"VB Programmer" <do**@emailme.c om> wrote in message
news:uS******** ******@TK2MSFTN GP11.phx.gbl...
Using ASP.NET 2.0...

My GridView is partially defined as such....

<asp:GridView ID="CartGrid" AutoGenerateCol umns="False"
DataKeyNames="I D" OnSelectedIndex Changed="Remove CartItem"
CellPadding="4"
runat="Server" ForeColor="Gray " GridLines="None " Width="90%"
BorderStyle="In set"
BorderWidth="1p x" Caption="Shoppi ng Cart" Font-Bold="False"
CaptionAlign="L eft">
<Columns>
<asp:ButtonFiel d
CommandName="se lect" Text="Remove" />
<asp:BoundFie ld
DataField="Name " HeaderText="Nam e">
<ControlStyle
Width="300px" />
<ItemStyle
Width="300px" />

As you can see, when the user clicks "Remove" it runs the
"RemoveCartItem " function, defined as such...

Sub RemoveCartItem( ByVal s As Object, ByVal e As EventArgs) Handles
CartGrid.Select edIndexChanged
Dim ID As String = CartGrid.Select edDataKey.Value
Profile.MyShopp ingCart.RemoveI tem(ID)
BindShoppingCar t()
End Sub
Sub BindShoppingCar t()
If Not Profile.MyShopp ingCart Is Nothing Then
CartGrid.DataSo urce = Profile.MyShopp ingCart.CartIte ms
CartGrid.DataBi nd()
lblTotal.Text = Profile.MyShopp ingCart.Total.T oString("c")
BindShippingDdl ()
End If
End Sub

I put a breakpoint on RemoveCartItem and the code is running twice each
time. Any ideas why?

Thanks!



Mar 23 '06 #4

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

Similar topics

4
336
by: Dan O. | last post by:
I have a button on my ASP.NET form that takes information from the form and puts it into a database. However, whenever I push that button it runs the function three times instead of just once. What can I do to fix this?
4
5128
by: Noxis | last post by:
I'm having problems with the OnSelectedIndexChanged event firing twice when a ListView item is selected and not at all if I click on an already selected index. I've read older postings and other people seem to have experienced the same problem, but it seems that it hasn't been addressed. If anyone can help, I would really appreciate it, Thanks
1
4417
by: Paul L | last post by:
Hi, I have an issue with the OnSelectedIndexChanged event not firing for a DropDownList control which is in the ItemTemplate of a DataList. I have made an exact copy of the DropDownList control, and placed it outside of the DataList and it fires the event just fine. So it's definitely to do with it being in a template. I've managed to reproduce the issue on a small test app, the code and html is below:
2
16085
by: glenn | last post by:
Hi folks, I am trying to determine which item in a DropDownList Web control has been selected. I have posted an OnSelectedIndexChanged subroutine in my code with a reference to the subroutine in my asp tag as shown here: <asp:DropDownList id="ddlTo" runat="server"
1
1861
by: Groove | last post by:
I have a strange problem. It seems that for some reason, a OnSelectedIndexChanged event is no producing an error in IE6. What concerns me is that I just performed that large Windows update a couple of weeks ago and it updated ActiveX "stuff" in IE. I'm not sure if the update has effected IE or there's something wrong with mt .net application. I have a simple DDL. It calls a sub when the value in the DDL is changed. Now, when I change...
8
5918
by: Learner | last post by:
Hello, I converted a VS 2003 project to VS 2005. It works perfectly alright in VS 2003 but when I try running in VS 2005 I got strange thing going on. The code (my button click event ) runs twice? Has any one run into this kind of situation before please help. Am I missing some thing here? or do I need to set an option here? Thanks, -L
7
1536
by: Just_a_fan | last post by:
I have a program which runs fine here (created in VB9). I publish it to my web site for download & install. It runs on some computers (one or two) but not others. When it does not run, it causes a reporting and submission window to pop up. It seems something is missing. This program was converted from a VB6 original piece. Unfortunately, I started on the .NET path just a couple of weeks after getting this app going. I have...
11
7321
by: Gord | last post by:
When I open a certain report, it runs some code that generates the records that will be displayed in that report. This works fine. When I go to print preview the report it appears that the code is run again? This is causing certain error problems. 1 Why does the code run for a print preview when the report already exists? 2 What command do I use in code to find out if a report (or any other object for that matter) is already...
3
4457
mshmyob
by: mshmyob | last post by:
I am scratching my head over this. I have a combo box control where the afterupdate event or even the onchange event keeps runnning twice. Below is some simple code to emulate the problem I am having. Assume combobox control is cboTest and command button control is cmdTest. Private Sub cboTest_AfterUpdate() MsgBox ("Change") End Sub
0
8471
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8386
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
8815
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
8592
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
7421
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...
1
6216
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5686
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
4213
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...
1
2802
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.