Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
!IsPostBack test causes cast error while saving
Message
De
28/03/2004 18:04:04
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
!IsPostBack test causes cast error while saving
Divers
Thread ID:
00890299
Message ID:
00890299
Vues:
61
Hi,

I am optimizing the performance of my web forms and I am up to analyzing the efficiency of my postbacks. I have one web form that has 4 read-only datagrids as look-ups and 14 TextBoxes bound to a Business Object named Patient. Each datagrid is bound to a data table via setting the DataGrid’s BindingSource property to the corresponding Business Object. I instantiate all of the business objects in the web form’s Page_load event and then I query the back end for the required records.
For example:
	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.

For example:
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.
For example :
  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?

Regards,
Neil
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform