Maintaining my original value through postbacks and Radio Button events

Posted on 2006-03-26
Last Modified: 2012-08-13
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_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged

        ViewState("OriginalPrice") = lblPrice.Text

        If RadioButtonList1.SelectedItem.Text = "Yes" Then
            lblPrice.Text = FormatCurrency(CInt(lblPrice.Text) + ((CInt(lblPrice.Text) / 100) * 30), 2)
            lblPrice.Text = FormatCurrency(ViewState("OriginalPrice"))
        End If

    End Sub

Question by:g-spot
    LVL 22

    Accepted Solution

    Could something like this work for you?

    If ViewState("OriginalPrice") Is Nothing Then ViewState("OriginalPrice") = lblPrice.Text

    Then it will only fill the ViewState, OriginalPrice, if it hasn't already been filled in.

    -- Jason

    Author Comment

    Thanks Jason. Thats perfect.

    I seem to be trying to make things more difficult for myself and am missing the obvious answers!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now