 |
| ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 4 General Discussion 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
|
|
|
|

April 9th, 2011, 04:38 PM
|
|
Authorized User
|
|
Join Date: Dec 2010
Posts: 21
Thanks: 4
Thanked 1 Time in 1 Post
|
|
Autopostback is messing with my Data Grid
I have a DropDownList with a list of the united states. When particular states are selected, the shipping price is supposed to change. The DropDownList is set to Autopostback = "True" and I put my code into the Page_Init subroutine because when I put it into the Page_Load subroutine, the subtotal is reset to "0.00" automatically.
What I want to know is:
How do I keep my Autopostback = "True" at the same time I am still able to calculate my subtotal and still get the shipping value that I want based on the state I select from the drop down list?
If you need explainations for ANY of the following code, get back to me IMMEDIATELY!
I have a meeting with our client on the 12th, and would really like to show him how awesome I am at this (and yeah, if you really care, I'll say something about you)
Code:
<script runat="server">
Dim objDT As System.Data.DataTable
Dim objDR As System.Data.DataRow
Private Sub Page_Init(s As Object, e As EventArgs) 'Originally it was Page_Load, but I changed it because it solved the issues I had with GetItemTotal()
Dim Counted As Boolean = CType(Session.Item("Counted"), Boolean)
lblTotal.Text = "$" & GetItemTotal()
Dim Shipping As Decimal
Dim Chocolate As Boolean = CType(Session.Item("Chocolate"), Boolean)
Dim WarmState As Boolean
If DropDownList1.SelectedValue = "AL" Then
WarmState = True
ElseIf DropDownList1.SelectedValue = "AR" Then
WarmState = True
ElseIf DropDownList1.SelectedValue = "FL" Then
WarmState = True
ElseIf DropDownList1.SelectedValue = "GA" Then
WarmState = True
ElseIf DropDownList1.SelectedValue = "LA" Then
WarmState = True
ElseIf DropDownList1.SelectedValue = "MS" Then
WarmState = True
ElseIf DropDownList1.SelectedValue = "NC" Then
WarmState = True
ElseIf DropDownList1.SelectedValue = "SC" Then
WarmState = True
ElseIf DropDownList1.SelectedValue = "TN" Then
WarmState = True
Else
WarmState = False
End If
If Month(Now) > 4 Then
If Month(Now) < 10 Then
If WarmState = True Then
If GetItemTotal() < 25.00 Then
Shipping = "55.00"
ElseIf GetItemTotal() < 50.00 Then
Shipping = "48.00"
ElseIf GetItemTotal() < 75.00 Then
Shipping = "41.00"
ElseIf GetItemTotal() < 100.00 Then
Shipping = "34.00"
ElseIf GetItemTotal() < 125.00 Then
Shipping = "27.00"
ElseIf GetItemTotal() < 150.00 Then
Shipping = "20.00"
ElseIf GetItemTotal() >= 150.00 Then
Shipping = "0.00"
End If
ElseIf WarmState = False Then
If Chocolate = False Then
If GetItemTotal() < 25.00 Then
Shipping = "13.50"
ElseIf GetItemTotal() < 50.00 Then
Shipping = "10.00"
ElseIf GetItemTotal() < 75.00 Then
Shipping = "5.00"
ElseIf GetItemTotal() < 100.00 Then
Shipping = "3.00"
ElseIf GetItemTotal() < 125.00 Then
Shipping = "0.00"
ElseIf GetItemTotal() < 150.00 Then
Shipping = "0.00"
ElseIf GetItemTotal() >= 150.00 Then
Shipping = "0.00"
End If
ElseIf Chocolate = True Then
If GetItemTotal() < 25.00 Then
Shipping = "36.50"
ElseIf GetItemTotal() < 50.00 Then
Shipping = "30.00"
ElseIf GetItemTotal() < 75.00 Then
Shipping = "24.00"
ElseIf GetItemTotal() < 100.00 Then
Shipping = "18.00"
ElseIf GetItemTotal() < 125.00 Then
Shipping = "13.50"
ElseIf GetItemTotal() < 150.00 Then
Shipping = "0.00"
ElseIf GetItemTotal() >= 150.00 Then
Shipping = "0.00"
End If
End If
End If
End If
End If
If Month(Now) <= 4 Or Month(Now) >= 10 Then
If WarmState = True Then
If GetItemTotal() < 25.00 Then
Shipping = "36.50"
ElseIf GetItemTotal() < 50.00 Then
Shipping = "30.00"
ElseIf GetItemTotal() < 75.00 Then
Shipping = "24.00"
ElseIf GetItemTotal() < 100.00 Then
Shipping = "18.50"
ElseIf GetItemTotal() < 125.00 Then
Shipping = "13.50"
ElseIf GetItemTotal() >= 125.00 Then
Shipping = "0.00"
End If
ElseIf WarmState = False Then
If Chocolate = False Then
If GetItemTotal() < 25.00 Then
Shipping = "13.50"
ElseIf GetItemTotal() < 50.00 Then
Shipping = "10.00"
ElseIf GetItemTotal() < 75.00 Then
Shipping = "5.00"
ElseIf GetItemTotal() < 100.00 Then
Shipping = "3.00"
ElseIf GetItemTotal() < 125.00 Then
Shipping = "0.00"
ElseIf GetItemTotal() >= 125.00 Then
Shipping = "0.00"
End If
ElseIf Chocolate = True Then
If GetItemTotal() < 25.00 Then
Shipping = "13.50"
ElseIf GetItemTotal() < 50.00 Then
Shipping = "10.00"
ElseIf GetItemTotal() < 75.00 Then
Shipping = "5.00"
ElseIf GetItemTotal() < 100.00 Then
Shipping = "3.00"
ElseIf GetItemTotal() < 125.00 Then
Shipping = "0.00"
ElseIf GetItemTotal() >= 125.00 Then
Shipping = "0.00"
End If
End If
End If
End If
lblTotal0.Text = "$" & Shipping
lblTotal1.Text = Shipping + GetItemTotal()
End Sub
Function GetItemTotal() As Decimal
Dim decRunningTotal As Decimal
If Not objDT is Nothing Then
For Each objDR In objDT.Rows
decRunningTotal += (objDR("Item Cost") * objDR("Quantity"))
Next
Else
decRunningTotal = "0.00"
End If
Return decRunningTotal
End Function
'|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
</script>
Last edited by MtheK; April 11th, 2011 at 08:40 AM..
|
|

April 10th, 2011, 04:28 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
I am so frustrated I could kill something!
|
I doubt this is the best way to attract viewers that want to help you IMMEDIATELY to show off how awesome you are......
That said, it's pretty unclear what your problem is (something with a DDL and a price; that's all I got from it). Secondly. the code doesn't really convey its awesomeness, so just by looking at the code alone it's impossible to see what the problem is or how it can be fixed. You may want to delete all code irrelevant to the problem....
Cheers,
Imar
|
|

April 10th, 2011, 11:01 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
try to store your subtotal in some hidden field or some view state variable
|
|

April 11th, 2011, 08:47 AM
|
|
Authorized User
|
|
Join Date: Dec 2010
Posts: 21
Thanks: 4
Thanked 1 Time in 1 Post
|
|
Dear Mr. Spaanjars (hope I spelled it right)
I have deleted the code that I think irrelevant to the problem as you suggested, and the program still doesn't work!
(just kidding, I made the changes in my comment above)
I am also aware of how unawesoeme it is. If it were awesome it would work.
Thanks
|
|

April 11th, 2011, 09:01 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
Dear Mr. Spaanjars (hope I spelled it right)
|
Nope, see, my signature.
Quote:
|
That said, it's pretty unclear what your problem is (something with a DDL and a price; that's all I got from it).
|
This hasn't changed much, has it?
Imar
Last edited by Imar; April 11th, 2011 at 09:06 AM..
|
|

April 11th, 2011, 12:23 PM
|
|
Authorized User
|
|
Join Date: Dec 2010
Posts: 21
Thanks: 4
Thanked 1 Time in 1 Post
|
|
Dear Mr. Spaanjaars,
I am sorry if I have offended you. I reviewed what I wrote and realize that I wasn't very clear. Let me explain again. When I select another state with my drop down list, the shipping value doesn't change, even though I have it programmed to do so on Page_Init.
That's the best I can explain it. If you still don't understand, I can send you a link to it.
|
|

April 11th, 2011, 02:41 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Init is too early for this. During Init, the values from the form and viewstate haven't been loaded into the controls yet. So, if your DDL causes a PostBack, it still has the first item as the selected value during Init.
For for more information on how this works, check out: http://msdn.microsoft.com/en-us/library/ms178472.aspx
Why don't you use the DLL's SelectedIndexChanged event? Sounds like a perfect candidate for this.
Cheers,
Imar
|
|
 |