protected void Page_Load(object sender, EventArgs e) { List <Person> contacts = KalleSQL.ReadListFromSql(); LiteralContacts.Text = JsonConvert.SerializeObject(contacts); //string contactTable = "<table><thead><tr><td>Firstname</td><td>Lastname</td><td>SSN</td></tr></thead>"; //contactTable += "<tbody>"; //foreach (var p in KalleSQL.ReadListFromSql()) //{ // contactTable += $"<tr><td><a href='/Contact.aspx?cid={p.ID}'>{p.FirstName}</td><td>{p.LastName}</td><td>{p.Ssn}</td></a></tr>"; //} //contactTable += "</tbody>"; //contactTable += "</table>"; //LiteralContacts.Text = contactTable; }
protected void Page_Load(object sender, EventArgs e) { if (Request["action"] != null) { string action = Request["action"].ToString(); if (action == "getAllContacts") { List <Person> contacts = KalleSQL.ReadListFromSql(); JSONLiteral.Text = JsonConvert.SerializeObject(contacts); } if (action == "addContact") { string firstName = Request["firstName"] != null ? Request["firstName"].ToString() : ""; string lastName = Request["lastName"] != null ? Request["lastName"].ToString() : ""; KalleSQL.AddContact(firstName, lastName, "12345"); JSONLiteral.Text = JsonConvert.SerializeObject("ok"); } } }