private void Page_Load(object sender, System.EventArgs e) { // get the patient identifier from the calling form string custid = Request.QueryString["custid"]; // register patient bizobj as primary this.oPatient = (Patient)this.RegisterPrimaryBizObj(new Patient()); // populate patient dataset and persist it across application Session["dsPatient"] = this.oPatient.GetPatientBycustid(custid); // Instantiate all of the look-up (read-only) business objects //register labwork bizobj this.oLabWork = (LabWork)this.RegisterBizObj(new LabWork()); //register letterlog bizobj this.oLetterLog = (LetterLog)this.RegisterBizObj(new LetterLog()); //register guarantor bizobj this.oGuarantor = (Guarantor)this.RegisterBizObj(new Guarantor()); //register model bizobj this.oModel = (Model)this.RegisterBizObj(new Model()); // populate all of the look-up (read-only) datasets and persist them across application // populate the LetterLog Dataset for this patient Session["dsLetterLog"] = this.oLetterLog.GetLetterLogByptno(custid); // populate the LabWork DataSet for this patient Session["dsLabWork"] = this.oLabWork.GetLabWorkBycustno(custid); // populate the Guarantor Dataset for this patient Session["dsGuarantor"] = this.oGuarantor.GetGuarantorBycustno(custid); //populate the Model Dataset for this patient Session["dsModel"] = this.oModel.GetModelBycustno(custid); }Everything at this point is working just fine. All of the look-up datagrids get populated. The changes I make to texboxes, bound to the Patient business object, are saved to the Patient data table after I run the following code in a Save button’s click event named btnSave.
private void btnSave_Click(object sender, System.EventArgs e) { DataSet dsPatient = (DataSet)Session["dsPatient"]; if (this.Save(this.oPatient, dsPatient, this.oPatient.TableName) == mmSaveDataResult.RulesPassed) { Response.Redirect("gmgWebPatients.aspx"); } }The problem occurs when I attempt to wrap the 4 read-only Business Objects and their queries in a “!IsPostBack” construct.
if (!IsPostBack) { // Instantiate look-up (read-only) business objects //register labwork bizobj this.oLabWork = (LabWork)this.RegisterBizObj(new LabWork()); //register letterlog bizobj this.oLetterLog = (LetterLog)this.RegisterBizObj(new LetterLog()); //register guarantor bizobj this.oGuarantor = (Guarantor)this.RegisterBizObj(new Guarantor()); //register model bizobj this.oModel = (Model)this.RegisterBizObj(new Model()); // populate look-up (read-only) datasets and persist across application // populate the LetterLog Dataset for this patient Session["dsLetterLog"] = this.oLetterLog.GetLetterLogByptno(custid); // populate the LabWork DataSet for this patient Session["dsLabWork"] = this.oLabWork.GetLabWorkBycustno(custid); // populate the Guarantor Dataset for this patient Session["dsGuarantor"] = this.oGuarantor.GetGuarantorBycustno(custid); //populate the Model Dataset for this patient Session["dsModel"] = this.oModel.GetModelBycustno(custid); }If I now hit btnSave I get the following error thrown:
Server Error in '/2004_gmg Web Application' Application. Specified cast is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Line 441: DataSet dsPatient = (DataSet)Session["dsPatient"]; Line 442: if (this.Save(this.oPatient, dsPatient, this.oPatient.TableName) == Line 443: mmSaveDataResult.RulesPassed) Line 444: { Source File: c:\inetpub\wwwroot\2004_gmg web application\patientedit.aspx.cs Line: 442 Stack Trace: [InvalidCastException: Specified cast is not valid.] OakLeaf.MM.Main.Web.UI.mmBusinessWebPage.BindBackPropertyBoundControls() OakLeaf.MM.Main.Web.UI.mmBusinessWebPage.Save(mmBusinessObject bizObj, DataSet ds, String tableName)Can anyone help me with this?