Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 11th, 2006, 03:44 PM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default values getting lost in button click

hi all,

i have a shopping cart, in which i can adjust qunatities,
when i edit quantity and then click the recalculate button, the values are lost from the datagrid, and also the total is shown as 0.00

given below is the code which i am using
can anyone please see and tell me, what is the mistake i hav done

Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim total As Decimal = 0

Try
For Each dgi As DataGridItem In DataGrid1.Items
If dgi.ItemType = ListItemType.Item OrElse dgi.ItemType = ListItemType.AlternatingItem Then
Dim t As TextBox = CType(dgi.Cells(3).Controls(1), TextBox)

Dim quantity As Integer = Integer.Parse(t.Text)
Dim unitprice As Decimal = Decimal.Parse(dgi.Cells(2).Text)
total = total + (unitprice * quantity)
Dim ShopCart2 As ShoppingCart.shopcart = New ShoppingCart.shopcart
ShopCart2.UpdateQuantity(Session.SessionID, Integer.Parse(dgi.Cells(0).Text), quantity)

End If
Next
Catch ex As Exception

End Try
lblAmt.Text = total.ToString("c")

End Sub

and in the class

Public Sub UpdateQuantity(ByVal CartID As String, ByVal ProductID As Integer, ByVal newQty As Integer)
Dim con As New SqlConnection("")
Dim cmd As New SqlCommand
cmd.Connection = con
cmd.CommandText = "update ShoppingCart set Quantity=@qty where CartID= @cartid and ProductID=@prodid"

Dim p1 As New SqlParameter("@qty", newQty)
Dim p2 As New SqlParameter("@cartid", CartID)
Dim p3 As New SqlParameter("@prodid", ProductID)

cmd.Parameters.Add(p1)
cmd.Parameters.Add(p2)
cmd.Parameters.Add(p3)

con.Open()
cmd.ExecuteNonQuery()
con.Close()

End Sub

THANKS


 
Old December 11th, 2006, 03:58 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

It doesnt appear that you are rebinding your data to anything...

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old December 11th, 2006, 04:05 PM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i am sorry, i am actually rebinding using the below code

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If Not Page.IsPostBack Then
            FillCartFromDB()
        End If

    End Sub

    Function FillCartFromDB()

        Dim ds As New DataSet
        ds = ShoppingCart.shopcart.GetAll(Session.SessionID)

        DataGrid1.DataSource = ds
        DataGrid1.DataBind()

        Button1_Click(Nothing, Nothing)

    End Function

 
Old December 11th, 2006, 04:09 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You bind isn't called. Your button posts the page back to itself and the FillCart method is never called; call FillCartFromDB in your button_click event.

Also, you have labeled FillCartFromDB as a function, its a method because it doesnt return a value.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old December 11th, 2006, 04:35 PM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

if i call the fillcartfromdb() from the button click, the application hangs.its not dispalying anything.

 
Old December 11th, 2006, 04:44 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Then something is wrong with how your are processing data and if it isnt throwing an error I couldn't even begin to tell you how to correct it.

What I can tell you with 100% certainity is that after you click the "recalculate" button is that the method FillCartFromDB is never called again. That will correct the problem of your datagrid not rebinding, however, you now need to figure out where your code is hanging out and why. Place a hook inside your class and step through your code and see what is going on.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old December 11th, 2006, 05:04 PM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i tried once more giving the fillcartfromdb() in buttonclick
the error coming is
Server Application Unavailable
The web application you are attempting to access on this web server is currently unavailable. Please hit the "Refresh" button in your web browser to retry your request.

Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server. Please review this log entry to discover what caused this error to occur.


 
Old December 11th, 2006, 05:11 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

That message means: Your aspnet_wp.exe process on the server is crashing. This normally happens when the .NET worker process consumes to much server resource and the process gets recycled by the server automatically. In your case, this problem is *probably* occuring because you have entered into an infinte loop or some process that takes an extremely long time to complete and, moreover, is consuming vast amounts of memory in the process.

You are going to have to step through your code on this one because, outside of a speicific error, I can't provide you any more info.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old December 11th, 2006, 05:13 PM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks Parsons.
i will step through the code in detail and try to figure out, if there is any infinite loop






Similar Threads
Thread Thread Starter Forum Replies Last Post
Values from recordset lost after reading vanik.cz Classic ASP Databases 11 January 4th, 2008 07:36 AM
Is it possible to button click Y/N in an email and kenn_rosie VB.NET 2002/2003 Basics 0 March 2nd, 2006 07:36 PM
Button Click ~Bean~ ASP.NET 1.0 and 1.1 Basics 2 September 27th, 2005 09:32 AM
Button acts depending on radio button values janise Access 4 March 10th, 2004 12:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.