R
Rosemary
I have been struggling with this for weeks. Each time I thought I had
it figured out, it has reared its ugly head again! Any help is
SO appreciated since my project deadline is Friday!!!!
************What I am trying to do:
I have a bunch of user controls that are loaded and unloaded one at a
time. Before one control is loaded, a SaveControl method is called to
save any changes the user made in the previous control.
************What is happening:
I am dynamically loading a user control in a place holder like this:
Control ctl = new Control();
ctl = LoadControl("AssessmentDemographics.ascx");
The control loads fine. A user is able to change values of controls
in the user control. Once they have made their changes, they click on
the next control they want to load. However, when the SaveControl
method in the usercontrol is triggered the first time, the changes are
saved. But then any other changes made are lost!
I have stepped through the code and watched the new values entered by
the user disappear. For example, a patient has been entered with the
first name of "John". The user changes the name to "Jack", but when
the SaveControl method is called and the first name property is being
set to the text box's text, it says the text box text still says John.
I am not sure what I am doing right the first time and doing wrong
every other time! I don't know what I am missing. I will post some
code to give a better idea of what I am doing. Hopefully it isn't as
confusing as I am feeling right now.
TIA,
Rosemary
//*****************CODE TO FOLLOW******************************
//---------------------------MAIN
PAGE------------------------------------------
//I have link buttons that a user can click to change which form they
are working on.
//Each time a link is clicked, the current form is saved, and the new
one loaded
protected void lnkDemographics_Click(object sender, EventArgs e)
{
//Utility is just a class I created to help me convert values
without having null errors, etc....
AGP.Utilities.Utility utility = new AGP.Utilities.Utility();
SaveCurrentControl();
//Form Order is simply an enum letting me save which Form ID is
currently loaded.
//I save that form id to a cookie.
SaveCurrentControlID(utility.GetInt32(AGP.Common.FormOrder.AssessmentDemographics));
LoadCurrentControl();
}
protected void lnkAssessmentMain_Click(object sender, EventArgs e)
{
AGP.Utilities.Utility utility = new AGP.Utilities.Utility();
SaveCurrentControl();
SaveCurrentControlID(utility.GetInt32(AGP.Common.FormOrder.AssessmentMain));
LoadCurrentControl();
}
private void LoadCurrentControl()
{
int controlID = GetCurrentControlID();
//If controlID = 0 then no control needs to be loaded, so exit the
method
if (controlID == 0)
{
return;
}
//Load the requested control
AGP.Utilities.Utility utility = new AGP.Utilities.Utility();
Control ctl = new Control();
placeHolder.Controls.Clear();
if (controlID ==
utility.GetInt32(AGP.Common.FormOrder.AssessmentDemographics))
{
this.lnkDemographics.BackColor = System.Drawing.Color.AliceBlue;
ctl = LoadControl("AssessmentDemographics.ascx");
}
else if (controlID ==
utility.GetInt32(AGP.Common.FormOrder.AssessmentMain))
{
this.lnkAssessmentMain.BackColor =
System.Drawing.Color.AliceBlue;
ctl = LoadControl("AssessmentMain.ascx");
}
placeHolder.Controls.Add(ctl);
}
private Boolean SaveCurrentControl()
{
//If the control to save is empty, then this is a first load and
no control needs saving yet
int controlID = GetCurrentControlID();
if (controlID == 0)
{
return false;
}
AGP.Utilities.Utility utility = new AGP.Utilities.Utility();
if (controlID ==
utility.GetInt32(AGP.Common.FormOrder.AssessmentDemographics))
{
UserControls_AssessmentDemographics currentControl =
(UserControls_AssessmentDemographics)placeHolder.Controls[0];
currentControl.SaveControl();
}
else if (controlID ==
utility.GetInt32(AGP.Common.FormOrder.AssessmentMain))
{
UserControls_AssessmentMain currentControl =
(UserControls_AssessmentMain)placeHolder.Controls[0];
currentControl.SaveControl();
}
return true;
}
private void SaveCurrentControlID(int controlID)
{
Session["CurrentControlID"] = controlID;
}
private void ClearCurrentControlID()
{
Session["CurrentControlID"] = null;
}
private int GetCurrentControlID()
{
if (Session["CurrentControlID"] == null)
{
return 0;
}
else
{
AGP.Utilities.Utility utility = new AGP.Utilities.Utility();
return utility.GetInt32(Session["CurrentControlID"]);
}
}
//-------------------------DEMOGRAPHICS USER
CONTROL----------------------------
//The second user control is very similar to this one,
//just uses a different class to update different properties.
protected void Page_Load(object sender, System.EventArgs e)
{
OpenAssessment();
}
private void OpenAssessment()
{
Patient patientToEdit = GetSelectedPatient();
Contract contract = GetSelectedContract();
AGP.Utilities.Utility utility = new AGP.Utilities.Utility();
this.txtFirstName.Text =
utility.GetString(patientToEdit.FirstName);
}
public void SaveControl()
{
Patient patient = GetSelectedPatient();
Utility utility = new Utility();
patient.FirstName = utility.GetString(txtFirstName.Text);
//Save the patient id for later retrieval
SavePatientID(new Patients().AddPatient(patient));
}
it figured out, it has reared its ugly head again! Any help is
SO appreciated since my project deadline is Friday!!!!
************What I am trying to do:
I have a bunch of user controls that are loaded and unloaded one at a
time. Before one control is loaded, a SaveControl method is called to
save any changes the user made in the previous control.
************What is happening:
I am dynamically loading a user control in a place holder like this:
Control ctl = new Control();
ctl = LoadControl("AssessmentDemographics.ascx");
The control loads fine. A user is able to change values of controls
in the user control. Once they have made their changes, they click on
the next control they want to load. However, when the SaveControl
method in the usercontrol is triggered the first time, the changes are
saved. But then any other changes made are lost!
I have stepped through the code and watched the new values entered by
the user disappear. For example, a patient has been entered with the
first name of "John". The user changes the name to "Jack", but when
the SaveControl method is called and the first name property is being
set to the text box's text, it says the text box text still says John.
I am not sure what I am doing right the first time and doing wrong
every other time! I don't know what I am missing. I will post some
code to give a better idea of what I am doing. Hopefully it isn't as
confusing as I am feeling right now.
TIA,
Rosemary
//*****************CODE TO FOLLOW******************************
//---------------------------MAIN
PAGE------------------------------------------
//I have link buttons that a user can click to change which form they
are working on.
//Each time a link is clicked, the current form is saved, and the new
one loaded
protected void lnkDemographics_Click(object sender, EventArgs e)
{
//Utility is just a class I created to help me convert values
without having null errors, etc....
AGP.Utilities.Utility utility = new AGP.Utilities.Utility();
SaveCurrentControl();
//Form Order is simply an enum letting me save which Form ID is
currently loaded.
//I save that form id to a cookie.
SaveCurrentControlID(utility.GetInt32(AGP.Common.FormOrder.AssessmentDemographics));
LoadCurrentControl();
}
protected void lnkAssessmentMain_Click(object sender, EventArgs e)
{
AGP.Utilities.Utility utility = new AGP.Utilities.Utility();
SaveCurrentControl();
SaveCurrentControlID(utility.GetInt32(AGP.Common.FormOrder.AssessmentMain));
LoadCurrentControl();
}
private void LoadCurrentControl()
{
int controlID = GetCurrentControlID();
//If controlID = 0 then no control needs to be loaded, so exit the
method
if (controlID == 0)
{
return;
}
//Load the requested control
AGP.Utilities.Utility utility = new AGP.Utilities.Utility();
Control ctl = new Control();
placeHolder.Controls.Clear();
if (controlID ==
utility.GetInt32(AGP.Common.FormOrder.AssessmentDemographics))
{
this.lnkDemographics.BackColor = System.Drawing.Color.AliceBlue;
ctl = LoadControl("AssessmentDemographics.ascx");
}
else if (controlID ==
utility.GetInt32(AGP.Common.FormOrder.AssessmentMain))
{
this.lnkAssessmentMain.BackColor =
System.Drawing.Color.AliceBlue;
ctl = LoadControl("AssessmentMain.ascx");
}
placeHolder.Controls.Add(ctl);
}
private Boolean SaveCurrentControl()
{
//If the control to save is empty, then this is a first load and
no control needs saving yet
int controlID = GetCurrentControlID();
if (controlID == 0)
{
return false;
}
AGP.Utilities.Utility utility = new AGP.Utilities.Utility();
if (controlID ==
utility.GetInt32(AGP.Common.FormOrder.AssessmentDemographics))
{
UserControls_AssessmentDemographics currentControl =
(UserControls_AssessmentDemographics)placeHolder.Controls[0];
currentControl.SaveControl();
}
else if (controlID ==
utility.GetInt32(AGP.Common.FormOrder.AssessmentMain))
{
UserControls_AssessmentMain currentControl =
(UserControls_AssessmentMain)placeHolder.Controls[0];
currentControl.SaveControl();
}
return true;
}
private void SaveCurrentControlID(int controlID)
{
Session["CurrentControlID"] = controlID;
}
private void ClearCurrentControlID()
{
Session["CurrentControlID"] = null;
}
private int GetCurrentControlID()
{
if (Session["CurrentControlID"] == null)
{
return 0;
}
else
{
AGP.Utilities.Utility utility = new AGP.Utilities.Utility();
return utility.GetInt32(Session["CurrentControlID"]);
}
}
//-------------------------DEMOGRAPHICS USER
CONTROL----------------------------
//The second user control is very similar to this one,
//just uses a different class to update different properties.
protected void Page_Load(object sender, System.EventArgs e)
{
OpenAssessment();
}
private void OpenAssessment()
{
Patient patientToEdit = GetSelectedPatient();
Contract contract = GetSelectedContract();
AGP.Utilities.Utility utility = new AGP.Utilities.Utility();
this.txtFirstName.Text =
utility.GetString(patientToEdit.FirstName);
}
public void SaveControl()
{
Patient patient = GetSelectedPatient();
Utility utility = new Utility();
patient.FirstName = utility.GetString(txtFirstName.Text);
//Save the patient id for later retrieval
SavePatientID(new Patients().AddPatient(patient));
}