protected void URLPopUpControlAddBankLedgerForThisLocation_OnBeforePopUpOpened(object sender, EventArgs e) { SaveDataIntoDataItemFromControls(); // create a new ledger and show this as a popup Ledger NewMat = new Ledger(); NewMat.LedgerType = "Bank"; NewMat.LimitToLocation = DataItem as Location; NewMat.LimitToLocation.BankLedger = NewMat; ControlObjectContext.AddToLedgerSet(NewMat); ControlObjectContext.SaveChanges(SaveOptions.DetectChangesBeforeSave); URLPopUpControlAddBankLedgerForThisLocation.URLToPopup = "webformpopup.aspx?uc=LedgerBase&Id=" + NewMat.Id.ToString(); }