Custom RadioButtonList on One Page Checkout

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
JimFriend
Ensign (ENS)
Ensign (ENS)
Posts: 10
Joined: Thu Jul 05, 2007 1:31 pm
Contact:

Custom RadioButtonList on One Page Checkout

Post by JimFriend » Mon Apr 06, 2009 2:48 pm

So I have a dynamic, custom RadioButtonList on the One Page Checkout. I need the customer to be able to select one of the options, and then when they click "Checkout" to complete their order I need to have the value of their selection inserted into a new table I created in the database.

So I have the RadioButtonList populating successfully, but when a customer selects one of the options the selection disappears when the customer clicks on a Payment Method. I noticed that several of the other values in the One Page Checkout are being saved using the LoadCustomViewState() and SaveCustomViewState() functions. So I tried adding my custom field information to the code inside those functions. I am now getting this error: "System.NullReferenceException: Object reference not set to an instance of an object." I have tried a bunch of different combinations without much success. I believe the issue lies with finding the actual control on the page and extracting that value. Here are the two functions listed above as I currently have them:

LoadCustomViewState()

Code: Select all

    private void LoadCustomViewState()
    {
        User user = Token.Instance.User;
        _CurrentBasketHash = user.Basket.GetContentHash(OrderItemType.Product);
        if (Page.IsPostBack)
        {
            UrlEncodedDictionary customViewState = new UrlEncodedDictionary(EncryptionHelper.DecryptAES(Request.Form[VS_CustomState.UniqueID]));
            _EditBillingAddress = (AlwaysConvert.ToInt(customViewState.TryGetValue("EditBillingAddress")) == 1);
            _EditShippingAddress = (AlwaysConvert.ToInt(customViewState.TryGetValue("EditShippingAddress")) == 1);
            _ShipToAddressId = AlwaysConvert.ToInt(customViewState.TryGetValue("ShipToAddressId"));
            _LastBillToCountry = customViewState.TryGetValue("LastBillToCountry");
            _BillToProvinceError = AlwaysConvert.ToBool(customViewState.TryGetValue("BillToProvinceError"), false);
            _LastShipToCountry = customViewState.TryGetValue("LastShipToCountry");
            _ShipToProvinceError = AlwaysConvert.ToBool(customViewState.TryGetValue("ShipToProvinceError"), false);
            _ShowBillToProvinceList = AlwaysConvert.ToBool(customViewState.TryGetValue("ShowBillToProvinceList"), false);
            _ShowShipToProvinceList = AlwaysConvert.ToBool(customViewState.TryGetValue("ShowShipToProvinceList"), false);
            CharityList.SelectedValue = customViewState.TryGetValue("CharitySelection");
            string savedBasketHash = customViewState.TryGetValue("SavedBasketHash");
            if (savedBasketHash == _CurrentBasketHash)
            {
                string savedShipRates = customViewState.TryGetValue("SavedShipRates");
                ParseSavedShipRates(savedShipRates);
            }
            _SavedBasketHash = savedBasketHash;
        }
        if (string.IsNullOrEmpty(_LastBillToCountry)) _LastBillToCountry = user.PrimaryAddress.CountryCode;
        if (string.IsNullOrEmpty(_LastShipToCountry)) _LastShipToCountry = GetDefaultShipToCountry(user);
    }
SaveCustomViewState()

Code: Select all

    
    private void SaveCustomViewState()
    {
        RadioButtonList selected = (RadioButtonList)PageHelper.RecursiveFindControl(Page, "CharityList");
        
        UrlEncodedDictionary customViewState = new UrlEncodedDictionary();
        customViewState.Add("EditBillingAddress", (_EditBillingAddress ? "1" : "0"));
        customViewState.Add("EditShippingAddress", (_EditShippingAddress ? "1" : "0"));
        customViewState.Add("ShipToAddressId", _ShipToAddressId.ToString());
        customViewState.Add("LastBillToCountry", BillToCountry.SelectedValue);
        customViewState.Add("BillToProvinceError", _BillToProvinceError.ToString());
        customViewState.Add("LastShipToCountry", ShipToCountry.SelectedValue);
        customViewState.Add("ShipToProvinceError", _ShipToProvinceError.ToString());
        customViewState.Add("SavedBasketHash", _CurrentBasketHash);
        customViewState.Add("SavedShipRates", EncodeSavedShipRates());
        customViewState.Add("ShowBillToProvinceList", _ShowBillToProvinceList.ToString());
        customViewState.Add("ShowShipToProvinceList", _ShowShipToProvinceList.ToString());
        customViewState.Add("CharitySelection", selected.SelectedItem.Value);
        VS_CustomState.Value = EncryptionHelper.EncryptAES(customViewState.ToString());
    }
The reason I say that I believe the issue lies with finding the actual control on the page and extracting that value, is because in the SaveCustomViewState() function, when I change this line:

Code: Select all

customViewState.Add("CharitySelection", selected.SelectedItem.Value);
to this:

Code: Select all

customViewState.Add("CharitySelection", "5");
The code works fine. In other words, if I hard-code a "5" for the selected value of the radio button, everything works ok.

Hopefully I explained the issue well enough. If anyone needs more information please let me know and I'll do my best to provide it as clearly as I can. Thanks in advance.
Jim Friend
Web Developer
Image

JimFriend
Ensign (ENS)
Ensign (ENS)
Posts: 10
Joined: Thu Jul 05, 2007 1:31 pm
Contact:

Re: Custom RadioButtonList on One Page Checkout

Post by JimFriend » Tue Apr 07, 2009 2:10 pm

I now have a solution for the problem above. I figured I'd post it here in case anyone else runs into a similar problem. Thanks to heinscott for figuring this out.

The issue was the placement of my DataBind'ing that was populating my custom radiobuttonlist. I had it in the Page_Load. It should have been in the TogglePanels() method. More specifically, it should be inside of the IF statement: if (!trAlreadyRegistered.Visible). This will allow the binding to happen, not when the page loads each time, but rather only when the registration process has not yet completed. So, the binding will happen on first page, but, not on second when visibility is set to "true".

Again, thanks to heinscott for figuring this one out.
Jim Friend
Web Developer
Image

Post Reply