g-spot
asked on
Maintaining my original value through postbacks and Radio Button events
I have a Radio Button SelectedIndexChanged event that adds 30% to a price if the relevant radio button ("Yes") is clicked.
However, if the person clicks the other radio button ("No") I want the price to revert back to the orginal price.
I cant seem to find a way to store the original price in the vewstate. The method below doesnt work properly as the viewstate takes the price from the actual textbox control (and this gets updated and increased everytime the user selects "Yes" in the Radio Button control. I need to store the price in the view state just once when the method is first run. I guess I need to use some kind of "counter" device that stores the number of times the Radio button has been selected.
Public Sub RadioButtonList1_SelectedI ndexChange d(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButtonList1.SelectedI ndexChange d
ViewState("OriginalPrice") = lblPrice.Text
If RadioButtonList1.SelectedI tem.Text = "Yes" Then
lblPrice.Text = FormatCurrency(CInt(lblPri ce.Text) + ((CInt(lblPrice.Text) / 100) * 30), 2)
Else
lblPrice.Text = FormatCurrency(ViewState(" OriginalPr ice"))
End If
End Sub
However, if the person clicks the other radio button ("No") I want the price to revert back to the orginal price.
I cant seem to find a way to store the original price in the vewstate. The method below doesnt work properly as the viewstate takes the price from the actual textbox control (and this gets updated and increased everytime the user selects "Yes" in the Radio Button control. I need to store the price in the view state just once when the method is first run. I guess I need to use some kind of "counter" device that stores the number of times the Radio button has been selected.
Public Sub RadioButtonList1_SelectedI
ViewState("OriginalPrice")
If RadioButtonList1.SelectedI
lblPrice.Text = FormatCurrency(CInt(lblPri
Else
lblPrice.Text = FormatCurrency(ViewState("
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I seem to be trying to make things more difficult for myself and am missing the obvious answers!!