protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var                  personid = Convert.ToInt32(Request.QueryString["ID"]);
                PeopleService        service  = new PeopleService();
                Contoso.Model.People person   = service.GetPersonById(personid);

                txtFirstName.Text = person.FirstName;
                txtLastName.Text  = person.LastName;
                txtAge.Text       = person.Age.ToString();
                txtEmail.Text     = person.Email;
                TxtPhone.Text     = person.Phone.ToString();
                txtAddress1.Text  = person.AddressLine1;
                txtUnit.Text      = person.UnitOrApartmentNumber.ToString();
                txtCity.Text      = person.City;
                txtZipcode.Text   = person.ZipCode.ToString();

                ddlStates.SelectedValue  = person.State;
                ddlStates.DataSource     = Utility.GetAllStates();
                ddlStates.DataTextField  = "StateName";
                ddlStates.DataValueField = "Value";
                ddlStates.DataBind();
            }
        }
示例#2
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     //check the server side control because the user/browser can disable the javascript.
     if (Page.IsValid)
     {
         Contoso.Model.People person = new Contoso.Model.People
         {
             FirstName    = txtFName.Text,
             LastName     = txtLastName.Text,
             MiddleName   = txtMiddleName.Text,
             AddressLine1 = txtAddress1.Text,
             AddressLine2 = txtAddress2.Text,
             Age          = Convert.ToInt32(txtAge.Text),
             State        = ddlStates.SelectedValue
         };
         PeopleService service = new PeopleService();
         service.SavePerson(person);
     }
 }
示例#3
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     if (Page.IsValid) //user can disable the javascript control, this checks the server side control
     {
         Contoso.Model.People peo = new Contoso.Model.People
         {
             FirstName             = txtFirstName.Text,
             LastName              = txtLastName.Text,
             MiddleName            = txtMiddleName.Text,
             Age                   = Convert.ToInt32(txtAge.Text),
             Email                 = txtEmail.Text,
             Phone                 = Convert.ToInt32(TxtPhone.Text),
             AddressLine1          = txtAddress1.Text,
             AddressLine2          = txtAddress2.Text,
             UnitOrApartmentNumber = Convert.ToInt32(txtUnit.Text),
             City                  = txtCity.Text,
             State                 = ddlStates.SelectedValue,
             ZipCode               = Convert.ToInt16(txtZipcode.Text)
         };
         PeopleService service = new PeopleService();
         service.SavePerson(peo);
     }
 }
 protected void btnUpdate_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         Contoso.Model.People peo = new Contoso.Model.People
         {
             Id                    = Convert.ToInt32(Request.QueryString["id"]),
             FirstName             = txtFirstName.Text,
             LastName              = txtLastName.Text,
             MiddleName            = txtMiddleName.Text,
             Age                   = Convert.ToInt32(txtAge.Text),
             Email                 = txtEmail.Text,
             Phone                 = Convert.ToInt32(TxtPhone.Text),
             AddressLine1          = txtAddress1.Text,
             AddressLine2          = txtAddress2.Text,
             UnitOrApartmentNumber = Convert.ToInt32(txtUnit.Text),
             City                  = txtCity.Text,
             State                 = ddlStates.SelectedValue,
             ZipCode               = Convert.ToInt16(txtZipcode.Text)
         };
         PeopleService service = new PeopleService();
         service.UpdatePerson(peo);
     }
 }