I have a user control in a web part that pulls data from a SP list and displays it in standard ASP.Net controls. When I save the data, the old values seem to get saved even if I had changed them. I debugged it in Visual Studio by attaching to the w3wp.exe process and put a breakpoint on a control reference in the save button commmand. Even though I changed the value in a control, its value in code at the breakpoint was still the old value. I am new to SP webpart development, so maybe I misundertsand something about how the viewstate and postbacks function in this situation.
I used WSPBuilder to create and deply the user control
Thanks.
-- Edit --
Here is the button code. When a breakpoint is inserted, none of the controls (like this.txtNotes.Text) have the new values I just typed in before clicking the save button even though I can see the new value in the UI control:
protected void btnSave_Click(object sender, EventArgs e)
{
ECORepository ecoRepository = new ECORepository();
ECO eco = new ECO();
eco.Originator = GetAccountName();
eco.Chemistry = this.ddlChemistry.SelectedValue;
eco.inProgressBox = this.inProgressBox.Checked;
eco.Model = this.txtModel.Text;
eco.Notes = this.txtNotes.Text;
eco.ReasonForChange = this.cblReasonForChange.SelectedValue;
eco.RedLine = this.chkRedLine.Checked;
eco.Tech = this.ddlTech.SelectedValue;
eco.Training = this.ddlTraining.SelectedValue;
if (String.IsNullOrEmpty(this.ecoID))
{
this.ecoID = ecoRepository.Add(eco).ToString();
}
else
{
eco.ECOID = this.ecoID;
ecoRepository.Edit(eco);
}
}
here is the edit method in my repository:
public void Edit(ECO entity)
{
SPSite Mysite = SPContext.Current.Site;
SPWeb MyWeb = SPContext.Current.Web;
string WebName = SPContext.Current.Web.Url;
try
{
MyWeb.AllowUnsafeUpdates = true;
Mysite.AllowUnsafeUpdates = true;
SPList ecoList = MyWeb.Lists["ECO"];
SPListItem ecoItem = ecoList.Items.GetItemById(Int32.Parse(entity.ECOID));
//ecoItem["Originator"] = headerEmptyCheck(entity.Originator);
ecoItem["Notes"] = headerEmptyCheck(entity.Notes);
ecoItem["Model"] = headerEmptyCheck(entity.Model);
ecoItem["Technology"] = headerEmptyCheck(entity.Tech);
ecoItem["Chemistry"] = headerEmptyCheck(entity.Chemistry);
ecoItem["Reason for Change"] = headerEmptyCheck(entity.ReasonForChange);
ecoItem["Training"] = headerEmptyCheck(entity.Training);
ecoItem["Red Line"] = entity.RedLine;
ecoItem["Wait for Workflow"] = entity.inProgressBox;
ecoItem.Update();
}
catch (Exception ex)
{
return;
}
}
finally, here is my ECO class:
public class ECO
{
public string ECOID { get; set; }
public string Originator { get; set; }
public string Notes { get; set; }
public string Model { get; set; }
public string Tech { get; set; }
public string Chemistry { get; set; }
public string ReasonForChange { get; set; }
public string Training { get; set; }
public bool RedLine { get; set; }
public bool inProgressBox { get; set; }
}
The repository and ECO are nested classes within the user control. I nested them just for testing because I wasnt sure if I could have them as separate classes in a user control in SharePpoint.