This project has moved. For the latest updates, please go here.


Use with webforms load/save typical scenarios


Hey there,
I'll try to simplify the scenario, so, not all the names and practices below are real world or topic for criticism:
Let's say I have EmployeeEntity object, and EditEmployee.aspx page, which has private field _employeeEntity.
In my Page_Load event I might have something like:
_employeeEntity = new EmployeeEntity( Request.QueryString["id"] );
if(!IsPostPack) LoadUIFromEmployeeModel();
Say I also have a Save button, where the button click is something like:
_employeeEntity.Save(); // or EmployeeRepository.Save(_employeeEntity); .. whatever
Cam Automapper help me with LoadUIFromEmployeeModel() and LoadEmployeeModelFromUI() ?
I mean, where the two functions look like:
txtName.Text = _employeeEntity.Name; //text box
chkIsActive.Checked = _employeeEntity.IsActive; //check box
ddlDepartmentId.Items.SelectByValue(_employeeEntity.DepartmentId); // drop down list
_employeeEntity.Name = txtName.Text; //text box
_employeeEntity.IsActive = chkIsActive.Checked; //check box
_employeeEntity.DepartmentId = ddlDepartmentId.SelectedValue; // drop down list
Can I automate this somehow using Automap?
If yes, what is the sample code of doing it?
Also, if yes, what are the limitations (for example, the drop down list line or say if I have the Name as two text boxes: txtName_FirstName mapping to _employeeEntity.Name.FirstName and txtName_LastName mapping to _employeeEntity.Name.LastName)?
Closed Sep 13, 2009 at 6:29 PM by jbogard
Solved with backing interface on ASPX page, I believe


jbogard wrote Aug 16, 2009 at 12:49 AM

I think I would do this with interfaces - make an IView that exposes the controls as simple properties, string Name { get; set; }. This is what I did when I used MVP with WebForms, it worked quite nicely. Then you only need to map IEmployeeView to Employee. Make sense?

wrote Sep 13, 2009 at 6:29 PM

wrote Feb 22, 2013 at 12:49 AM

wrote May 16, 2013 at 11:59 AM