cancel
Showing results for 
Search instead for 
Did you mean: 

New Address creation on Shipping Page

Former Member
0 Kudos

Hey All,

I have a .net user control running on the shipping.aspx page that retrieves the selected address from the drop down list or radio button of addresses in the users account.

This works great for existing addresses and I can save the info.

How can my control know what the address ID is when the user adds a new address? I get the order.GetShippingId it always has the value of the last selected address when adding a new address or 0 which is no good.

Any suggestions on how I can figure out what address ID has been assigned to the new address that was created?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Curtis,

Since my previous suggestions haven't panned out, I guess you can try getting it form the account object or go straight to the DB.


NPBasePage bp = (NPBasePage)Page;

NPAccount a = new NPAccount(bp.AccountID);

// get the last address in the collection
NPAddress address = null;
if (a.Addresses.Count > 0){
   address = ((NPAddress)a.Addresses[a.Addresses.Count -1]);
}
if (address != null){
    int addressid = address.AddressID;
}

Note that addresses are not sorted in the NPAddress.Addresses query, so it is possible that SQL Server will not return them in order of AddressID. If you are worried about this, you can check the ids to make sure you've got the highest. That will be the one that was just created.

or you could go straight to the DB:


NPBasePage bp = (NPBasePage)Page;

StringBuilder sb = new StringBuilder();

sb.Append("SELECT TOP 1 AddressID ");
sb.Append("FROM UsersAccountAddress ");
sb.Append("WHERE AccountID = @accountid ");
sb.Append("ORDER BY AddressID DESC");

DataParameters dp = new DataParameters(1);

dp.Add(NPDataType.NPInt, "@accountid", bp.AccountID);

object o = DataFunctions.ExecuteScalar(sb.ToString(), bp.Parameters, bp.ConnectionString);

if (o != null){
  int addressID = Convert.ToInt32(o);
}

Former Member
0 Kudos

Thanks Shane those two will definitely work. Appreciate the help

Former Member
0 Kudos

my pleasure

Answers (0)