protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (HttpContext.Current.Session["userid"] != null)
                {
                    //Check if user have right credit
                    //IF level == Provdeltahare
                    Classes.clsLogin clsLog = new Classes.clsLogin();
                    if (clsLog.getLevel(HttpContext.Current.Session["userid"].ToString()) == "deltagare") //Inloggad
                    {
                        //Label2.Text = HttpContext.Current.Session["userid"].ToString();
                    }
                    else //Är inloggad med fel credinatl
                    {
                        Response.Redirect("default.aspx");
                    }
                }
                else //Har inte loggat in
                {
                    Response.Redirect("login.aspx");
                }
            }

            if (ViewState["testID"] != null || Convert.ToString(ViewState["testID"]) != "")
            {
                testID = ViewState["testID"].ToString();
            }
            else
            {
                int tstID;
                clsStartingTest clsTestID = new clsStartingTest();
                testID = clsTestID.getTestid(HttpContext.Current.Session["userid"].ToString());
                if (int.TryParse(testID, out tstID))
                {
                    ViewState["testID"] = testID;
                }
                else
                {
                    Response.Redirect("default.aspx");
                }
            }

            if (!IsPostBack)
            {
                Classes.clsStartingTest clsSt = new Classes.clsStartingTest();
                clsSt.checkLasttest(HttpContext.Current.Session["userid"].ToString());
                clsTestMenuFill menu = new clsTestMenuFill();
                DataTable dtQuestions = menu.read(testID);
                for (int i = 0; i < dtQuestions.Rows.Count; i++)
                {
                    Label quNam = new Label();
                    quNam.Text = "<h3>" + dtQuestions.Rows[i]["name"].ToString() + "</h3>";
                    panData.Controls.Add(quNam);
                    fillData(dtQuestions.Rows[i]["id"].ToString(), testID);
                }
                Label qutNam = new Label();
                qutNam.Text = "<br/> <br />";
                panData.Controls.Add(qutNam);
                result(ViewState["testID"].ToString());
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (HttpContext.Current.Session["userid"] != null)
                {

                    Classes.clsLogin clsLog = new Classes.clsLogin();
                    if (clsLog.getLevel(HttpContext.Current.Session["userid"].ToString()) == "deltagare") //Inloggad
                    {
                        Label2.Text = HttpContext.Current.Session["userid"].ToString();
                    }
                    else //Är inloggad med fel credinatl
                    {
                        Response.Redirect("default.aspx");
                    }
                }
                else //Har inte loggat in
                {
                    Response.Redirect("login.aspx");
                }
                if (ViewState["testID"] != null || Convert.ToString(ViewState["testID"]) != "")
                {
                    testID = ViewState["testID"].ToString();
                }
                else
                {
                    int tstID;
                    clsStartingTest clsTestID = new clsStartingTest();
                    testID = clsTestID.getTestid(HttpContext.Current.Session["userid"].ToString());
                    if (int.TryParse(testID, out tstID))
                    {
                        ViewState["testID"] = testID;
                    }
                }
                // ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:timeToEnd(); ", true); //Skapar en timer för nedräkning javascript
                Label2.Text = Label2.Text + "  testID_ " + testID;
                Classes.clsTestMenuFill clMenFill = new Classes.clsTestMenuFill();
                cmbChooseQue.DataValueField = "id";
                cmbChooseQue.DataTextField = "name";
                cmbChooseQue.DataSource = clMenFill.read(testID);
                cmbChooseQue.DataBind();
                cmbChooseQue.Enabled = false;
                if (cmbChooseQue.Items.Count > 0) //Om den inte hämtat någon data så blir det felmedelande
                {
                    ViewState["alfred"] = cmbChooseQue.SelectedItem.ToString();
                    fillquestion();
                }
                else
                {
                    Label1.Text = "Något gick fel försök igen";
                    btnNext.Enabled = false;
                    btnPrevious.Enabled = false;
                    rbQuestionList.Enabled = false;
                    cmbChooseQue.Enabled = false;
                }
            }
            else
            {
                testID = ViewState["testID"].ToString();
            }
            if (btnNext.Text == "Lämna in")
            {
                checkAnswers();
                clsMethods clMeth = new clsMethods();
                clsFillQuestion clQue = new clsFillQuestion();
                clsRightOrNot clRi = new clsRightOrNot();

                string handle = clRi.canHandIn(ViewState["testID"].ToString());
                if (handle == "TIDEN DROG ÖVER")
                {
                    clRi.setFail(ViewState["testID"].ToString()); //Om tiden har gått över 30min så har man failat
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "UpdateMsg", "alert('Du lämnade in testet för sent du blir underkänd');", true);
                    Response.Redirect("default.aspx");
                    return;
                }
                else if(handle != "OK")
                {
                    return;
                }
                string xml = clQue.getXml(ViewState["testID"].ToString());
                Tuple<bool, List<int>, List<int>, int, int> aa = clMeth.PartAndTotalResult(clMeth.XmlToClasses(xml));//list1,
                bool resultP = aa.Item1;
                //Debug.WriteLine("TESTID " + testID + "  " + resultP.ToString() + " res och " + aa.Item4.ToString() + " till sist " + aa.Item5);
                clRi.updateResult(ViewState["testID"].ToString(), resultP);
                Response.Redirect("webbtestresult.aspx");
            }
            string start;
            if (ViewState["startime"] == null)
            {
                clsSetGetStarttime clSta = new clsSetGetStarttime();
                start = clSta.getStarttime(ViewState["testID"].ToString()).ToString();
                ViewState.Add("startime", start.ToString());
            }
            else
            {
                start = ViewState["startime"].ToString();
            }
            ClientScript.RegisterStartupScript(GetType(), "Javascript", "CallHandler('" + start + "'); ", true);
        }