473,379 Members | 1,530 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,379 software developers and data experts.

OnSelectedIndexChanged runs twice!

Using ASP.NET 2.0...

My GridView is partially defined as such....

<asp:GridView ID="CartGrid" AutoGenerateColumns="False"
DataKeyNames="ID" OnSelectedIndexChanged="RemoveCartItem"
CellPadding="4" runat="Server"
ForeColor="Gray" GridLines="None" Width="90%"
BorderStyle="Inset"
BorderWidth="1px" Caption="Shopping Cart" Font-Bold="False"
CaptionAlign="Left">
<Columns>
<asp:ButtonField
CommandName="select" Text="Remove" />
<asp:BoundField
DataField="Name" HeaderText="Name">
<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.SelectedIndexChanged
Dim ID As String = CartGrid.SelectedDataKey.Value
Profile.MyShoppingCart.RemoveItem(ID)
BindShoppingCart()
End Sub
Sub BindShoppingCart()
If Not Profile.MyShoppingCart Is Nothing Then
CartGrid.DataSource = Profile.MyShoppingCart.CartItems
CartGrid.DataBind()
lblTotal.Text = Profile.MyShoppingCart.Total.ToString("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 1468
FYI: Even AFTER I comment out the BindShoppingCart call it still calls
RemoveCartItem twice...

Any ideas?

"VB Programmer" <do**@emailme.com> wrote in message
news:uS**************@TK2MSFTNGP11.phx.gbl...
Using ASP.NET 2.0...

My GridView is partially defined as such....

<asp:GridView ID="CartGrid" AutoGenerateColumns="False"
DataKeyNames="ID" OnSelectedIndexChanged="RemoveCartItem"
CellPadding="4" runat="Server"
ForeColor="Gray" GridLines="None" Width="90%"
BorderStyle="Inset"
BorderWidth="1px" Caption="Shopping Cart" Font-Bold="False"
CaptionAlign="Left">
<Columns>
<asp:ButtonField
CommandName="select" Text="Remove" />
<asp:BoundField
DataField="Name" HeaderText="Name">
<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.SelectedIndexChanged
Dim ID As String = CartGrid.SelectedDataKey.Value
Profile.MyShoppingCart.RemoveItem(ID)
BindShoppingCart()
End Sub
Sub BindShoppingCart()
If Not Profile.MyShoppingCart Is Nothing Then
CartGrid.DataSource = Profile.MyShoppingCart.CartItems
CartGrid.DataBind()
lblTotal.Text = Profile.MyShoppingCart.Total.ToString("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.SelectedIndexChanged" from
RemoveCartItem and it works. It was calling twice, once from the dg and
once from the SelectedIndexChanged event I suppose.

"VB Programmer" <do**@emailme.com> wrote in message
news:uf**************@TK2MSFTNGP11.phx.gbl...
FYI: Even AFTER I comment out the BindShoppingCart call it still calls
RemoveCartItem twice...

Any ideas?

"VB Programmer" <do**@emailme.com> wrote in message
news:uS**************@TK2MSFTNGP11.phx.gbl...
Using ASP.NET 2.0...

My GridView is partially defined as such....

<asp:GridView ID="CartGrid" AutoGenerateColumns="False"
DataKeyNames="ID" OnSelectedIndexChanged="RemoveCartItem"
CellPadding="4" runat="Server"
ForeColor="Gray" GridLines="None" Width="90%"
BorderStyle="Inset"
BorderWidth="1px" Caption="Shopping Cart" Font-Bold="False"
CaptionAlign="Left">
<Columns>
<asp:ButtonField
CommandName="select" Text="Remove" />
<asp:BoundField
DataField="Name" HeaderText="Name">
<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.SelectedIndexChanged
Dim ID As String = CartGrid.SelectedDataKey.Value
Profile.MyShoppingCart.RemoveItem(ID)
BindShoppingCart()
End Sub
Sub BindShoppingCart()
If Not Profile.MyShoppingCart Is Nothing Then
CartGrid.DataSource = Profile.MyShoppingCart.CartItems
CartGrid.DataBind()
lblTotal.Text = Profile.MyShoppingCart.Total.ToString("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.com> wrote in message
news:u3**************@TK2MSFTNGP11.phx.gbl...
Got it! I removed "Handles CartGrid.SelectedIndexChanged" from
RemoveCartItem and it works. It was calling twice, once from the dg and
once from the SelectedIndexChanged event I suppose.

"VB Programmer" <do**@emailme.com> wrote in message
news:uf**************@TK2MSFTNGP11.phx.gbl...
FYI: Even AFTER I comment out the BindShoppingCart call it still calls
RemoveCartItem twice...

Any ideas?

"VB Programmer" <do**@emailme.com> wrote in message
news:uS**************@TK2MSFTNGP11.phx.gbl...
Using ASP.NET 2.0...

My GridView is partially defined as such....

<asp:GridView ID="CartGrid" AutoGenerateColumns="False"
DataKeyNames="ID" OnSelectedIndexChanged="RemoveCartItem"
CellPadding="4"
runat="Server" ForeColor="Gray" GridLines="None" Width="90%"
BorderStyle="Inset"
BorderWidth="1px" Caption="Shopping Cart" Font-Bold="False"
CaptionAlign="Left">
<Columns>
<asp:ButtonField
CommandName="select" Text="Remove" />
<asp:BoundField
DataField="Name" HeaderText="Name">
<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.SelectedIndexChanged
Dim ID As String = CartGrid.SelectedDataKey.Value
Profile.MyShoppingCart.RemoveItem(ID)
BindShoppingCart()
End Sub
Sub BindShoppingCart()
If Not Profile.MyShoppingCart Is Nothing Then
CartGrid.DataSource = Profile.MyShoppingCart.CartItems
CartGrid.DataBind()
lblTotal.Text = Profile.MyShoppingCart.Total.ToString("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
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...
4
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...
1
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,...
2
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...
1
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...
8
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...
7
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...
11
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...
3
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.