Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 13th, 2006, 09:22 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: norcross, Ga, USA.
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem of infinite loop

hi

i am facing a problem of infinite loop from the below sequence of code.
can anyone help me, how can i re arrange, so that i can get rid of ifinite loop and get the lblamt also displayed.

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

    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)

                    FillCartFromDB()
                     End If

            Next

        Catch ex As Exception

        End Try

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

    End Sub

if i take out the button1_click(nothing, nothing) from FillCartFromDB(), total is not getting displayed.
if i put FillCartFromDB() in button_clcik, the application hangs.

can anyone please advise me, how to solve this?

thanks

  #2 (permalink)  
Old December 13th, 2006, 09:28 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there...

for what i see...

you call fillcartfromdb(), that's call the button1_click, then you call fillcartfromdb again and it call button1_click, so you are coming an going within two functions and that's why it hangs..
maybe the logic is not good?

HTH

Gonzalo
  #3 (permalink)  
Old December 13th, 2006, 09:28 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hmm. First the reason you are being sent into an infitie loop is because is you call FillCartFromDB() from the Click Event, and then you call the click event from FillCart etc. Remove your Try Catch block and see if there is an exception being thrown because that seems most likely.

-------------------------
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
  #4 (permalink)  
Old December 13th, 2006, 09:35 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: norcross, Ga, USA.
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i removed the try catch block, the application hangs, it doesn't show any exceptions

  #5 (permalink)  
Old December 13th, 2006, 09:39 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

What line does it hang on? Did you remove the call to the click event from FillCart?

-------------------------
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
  #6 (permalink)  
Old December 13th, 2006, 09:44 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: norcross, Ga, USA.
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i removed the call event from fillcartfromdb()
also removed try catch block
when i view it in browser, and navigate through pages, at the shopping cart page, total is not displayed.
when i clciked the button1, it says

System.FormatException: Input string was not in a correct format.

Source Error:


Line 69:
Line 70: Dim quantity As Integer = Integer.Parse(t.Text)
Line 71: Dim unitprice As Decimal = Decimal.Parse(dgi.Cells(2).Text)
Line 72: total = total + (unitprice * quantity)
Line 73:


Source File: C:\Inetpub\wwwroot\ShoppingCart3VB\MyCart.aspx.vb Line: 71

Stack Trace:


[FormatException: Input string was not in a correct format.]
   System.Number.ParseDecimal(String s, NumberStyles style, NumberFormatInfo info) +0
   System.Decimal.Parse(String s, NumberStyles style, IFormatProvider provider) +30
   System.Decimal.Parse(String s) +9
   ShoppingCart3VB.MyCart.Button1_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\ShoppingCart3VB\MyCart.aspx.vb: 71
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
   System.Web.UI.Page.ProcessRequestMain() +1292




  #7 (permalink)  
Old December 13th, 2006, 09:52 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I knew there was an error somewhere ;] Whatever is in this cell dgi.Cells(2).Text cannot be parsed to a Decimal or it doesnt like the way the number is formated. For example if the cell contains $100 that will not parse correctly because of the $ character.

Verify the contents of that cell.

-------------------------
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
  #8 (permalink)  
Old December 13th, 2006, 10:21 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: norcross, Ga, USA.
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

UnitPRice is the field which causes the error.
actually in the table, UnitPrice has datatype set to float.

in the application, in the Product details page, i am displaying the UnitPrice through

lblprice.Text = Decimal.Parse(dr.Item("UnitPrice")).ToString("c")

then in the details page, when i clcik addtocart button, i am redirecting to shoppingcart page, and at the same time, adding the item details to shoppingcart table, in which i am adding the UnitPrice as

 item.UnitPrice = (lblprice.Text).ToString

this is facilitated through a user defined class, in which i have UnitPRice as

Public Property UnitPrice() As Decimal
            Get
                Return decUnitPrice
            End Get
            Set(ByVal Value As Decimal)
                decUnitPrice = Value
            End Set
        End Property

and finally in the shoppingcart page,
i am displaying the unitprice, not in dollars(in the datagrid)
and in the code

 Dim unitprice As Decimal = Decimal.Parse(dgi.Cells(2).Text)

this is the sequence in which the UnitPrice goes.

i am not able to figure out, changing which part can resolve my problem

can you please suggest some way?
thanks

  #9 (permalink)  
Old December 13th, 2006, 10:46 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ummm.

Decimal.Parse(dr.Item("UnitPrice")).ToString("c") <--- say that the value of unit price is 150 by using the format parameter c it will render as $150.00 (of course HOW it displays exactly will differ, for me it would be with a dollar ($) sign.)

So your label has a value of $150.00 then you pass in this:

item.UnitPrice = (lblprice.Text).ToString

Problem is, unitprice is a decimal but the label text is $150.00(and btw, if you were using C# the above line would throw an error about implicitly converting a string to a decimal). In this case, that is an invalid cast from a string to decimal.

All i can tell you for sure, is that you are trying to convert a value that can not be converted correctly.

-------------------------
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
  #10 (permalink)  
Old December 13th, 2006, 11:01 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: norcross, Ga, USA.
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i changed it to

 lblprice.Text = dr.Item("UnitPrice")

item.UnitPrice = Decimal.Parse(lblprice.Text)

 Dim unitprice As Decimal = Convert.ToDecimal(dgi.Cells(2).Text)

again the same error.

how can i resolve this?
thanks

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
infinite loop smilesmita Pro PHP 1 December 21st, 2007 10:44 AM
infinite recursion bangbangbogi XSLT 3 May 4th, 2006 05:54 AM
problem getting out of infinite loop and incremtin method VB How-To 0 April 28th, 2006 11:45 PM
How to Write a Infinite Loop Detection jtdang77 Classic ASP Professional 1 October 15th, 2003 03:44 AM
Infinite Loop Detection jtdang77 Classic ASP Basics 0 October 14th, 2003 05:32 PM



All times are GMT -4. The time now is 10:19 PM.


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