protected void Page_Load(object sender, EventArgs e) { string userkey = Request.QueryString["userkey"]; questionsWrap.Attributes.Add("userkey", userkey); Guid gu = new Guid(userkey); SQL sql = new SQL(); bool hasTaken = sql.checkIFTaken(gu); if (hasTaken) { string name = sql.CheckCandidate(gu); username.InnerText = "Candidate: " + name; int testId = sql.getTestID(gu); List<questions> list = GetQuestions(testId); foreach (questions q in list) { switch (q.qtype) { case 1: //create textarea StringBuilder sbq = new StringBuilder(); sbq.Append("<div class='well well-small'>"); sbq.Append("<p>" + q.question + "</p>"); sbq.Append("<textarea class='span12' qid='" + q.question_id + "' runat='server' "); sbq.Append("onKeyDown='limitText(this, 2600);' "); sbq.Append("onKeyUp='limitText(this, 2600);' >"); sbq.Append("</textarea></div>"); questionsWrap.InnerHtml += sbq.ToString(); break; case 2: //create true/false StringBuilder sbtf = new StringBuilder(); sbtf.Append("<div class='well well-small'>"); sbtf.Append("<p>" + q.question + "</p>"); sbtf.Append("<select qid='" + q.question_id + "'><option>true</option><option>false</option></select>"); sbtf.Append("</div>"); questionsWrap.InnerHtml += sbtf.ToString(); break; default: //nothing break; } } startTime(gu, DateTime.Now); } else { Response.Redirect("Entry.aspx"); } }
protected void btnCheck_Click(object sender, EventArgs e) { SQL sql = new SQL(); try { Guid gu = new Guid(key.Value.Trim().ToString()); bool hasTaken = sql.checkIFTaken(gu); if (hasTaken) { string name = sql.CheckCandidate(gu); if (name == null) { throw new NullReferenceException(); } int allowed_time = sql.getAllowedTime(gu); time.InnerText = allowed_time.ToString() + " Minutes"; Username.Value = name; if (error.Visible == true) { error.Visible = false; complete.Visible = true; key.Disabled = true; } else { complete.Visible = true; key.Disabled = true; } } else { if (complete.Visible == true) { complete.Visible = false; error.Visible = true; error.InnerText = "It looks like you have already taken this test!"; } else { error.Visible = true; error.InnerText = "It looks like you have already taken this test!"; } } } catch(NullReferenceException){ if (complete.Visible == true) { complete.Visible = false; error.Visible = true; } else { error.Visible = true; } } catch (Exception) { if (complete.Visible == true) { complete.Visible = false; error.Visible = true; } else { error.Visible = true; } } }