0
I did some research and couldn’t find the correct term to correct my mistake.
I created a Appweb where the user chooses a subject in a DropDownList
and this loads a questionnaire from the database.
What happens is that if there is simultaneous access several different errors occur:
- The most recurrent is the first user questionnaire to be loaded
for the second, even if he chose another option in
DropDownList
. - If I choose an option on
DropDownList
, load the questionnaire and return immediately to choose another option, is loaded to first option. Whereas, if I take a while and do the same process, load new choice.
I checked in the browser that the request is correct (Params) but the answer (Response) sends the page according to the previous parameters.
Apparently it is not accepting more than a user doing the questionnaire, and the server keeps the first choice in the cache and does not update the page even with a new parameter.
I hope you have understood and can help me.
Aspx code:
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<style type="text/css">
.modalPopup
{
background-color: #fffddd;
padding: 3px;
z-index: 10001;
}
</style>
<div class="panel panel-default">
<div id="divtest" runat="server">
<asp:Label ID="label" runat="server" Text="Escolha uma disciplina abaixo:"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" CssClass="dropdown form-control" OnSelectedIndexChanged="btnCarregarClick">
<asp:ListItem Enabled="false">Português</asp:ListItem>
<asp:ListItem >Racíocinio</asp:ListItem>
<asp:ListItem Enabled="false">História</asp:ListItem>
<asp:ListItem Enabled="false">Geografia</asp:ListItem>
<asp:ListItem >Direito Constitucional</asp:ListItem>
<asp:ListItem >Outros Direitos</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnCarregar" runat="server" Text="Carregar" CssClass ="btn btn-primary" OnClick="btnCarregarClick"/>
</div>
<div class ="panel-body col-md-12">
<asp:Panel ID="UpdPanel" runat="server">
<table id="tbl">
<tr>
<asp:Label ID="Label1" runat="server" Text="Label" Visible="false"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" OnSelectedIndexChanged="rdbList1_SelectedIndexChanged"></asp:RadioButtonList>
</tr><tr>
<asp:Label ID="Label2" runat="server" Text="Label" Visible="false"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList2" runat="server" OnSelectedIndexChanged="rdbList2_SelectedIndexChanged"></asp:RadioButtonList></tr><tr>
<asp:Label ID="Label3" runat="server" Text="Label" Visible="false"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList3" runat="server" OnSelectedIndexChanged="rdbList3_SelectedIndexChanged"></asp:RadioButtonList></tr><tr>
<asp:Label ID="Label4" runat="server" Text="Label" Visible="false"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList4" runat="server" OnSelectedIndexChanged="rdbList4_SelectedIndexChanged"></asp:RadioButtonList></tr><tr>
<asp:Label ID="Label5" runat="server" Text="Label" Visible="false"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList5" runat="server" OnSelectedIndexChanged="rdbList5_SelectedIndexChanged"></asp:RadioButtonList></tr><tr>
<asp:Label ID="Label6" runat="server" Text="Label" Visible="false"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList6" runat="server" OnSelectedIndexChanged="rdbList6_SelectedIndexChanged"></asp:RadioButtonList></tr><tr>
<asp:Label ID="Label7" runat="server" Text="Label" Visible="false"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList7" runat="server" OnSelectedIndexChanged="rdbList7_SelectedIndexChanged"></asp:RadioButtonList></tr><tr>
<asp:Label ID="Label8" runat="server" Text="Label" Visible="false"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList8" runat="server" OnSelectedIndexChanged="rdbList8_SelectedIndexChanged"></asp:RadioButtonList></tr><tr>
<asp:Label ID="Label9" runat="server" Text="Label" Visible="false"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList9" runat="server" OnSelectedIndexChanged="rdbList9_SelectedIndexChanged"></asp:RadioButtonList></tr><tr>
<asp:Label ID="Label10" runat="server" Text="Label" Visible="false"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList10" runat="server" OnSelectedIndexChanged="rdbList10_SelectedIndexChanged"></asp:RadioButtonList></tr>
</table>
</asp:Panel>
<asp:Button Visible="false" ID="btnCorrigir" runat="server" Text="Corrigir" CssClass ="btn btn-primary" OnClick="btnCorrigir_Click"/>
<asp:Label ID="lbll" Visible="false" Style="font-size:x-large" runat="server"></asp:Label>
<asp:Label ID="lblll" Visible="false" runat="server">Clique em gabarito para vê-lo.</asp:Label>
<asp:Button ID="btnok" CssClass="btn btn-primary" Visible="false" runat="server" Text="Gabarito" OnClick="btnok_click" />
<asp:LinkButton ID="Linkbtn" CssClass="btn btn-danger" Visible="false" runat="server" Text="Voltar" PostBackUrl="~/Default.aspx" />
<div ID="div" runat="server" visible="False">
<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: table" >
<table style="width: 270px">
<tr>
<td>
<asp:Label ID="lblGabarito" runat="server" Height="30px" Text="Gabarito"></asp:Label>
</td>
</tr>
<tr>
<td style="width: 30% ">
<asp:Label ID="lblPergunta1" runat="server" Height="30px"></asp:Label>
<asp:Label ID="lblPergunta2" runat="server" Height="30px"></asp:Label>
<asp:Label ID="lblPergunta3" runat="server" Height="30px"></asp:Label>
<asp:Label ID="lblPergunta4" runat="server" Height="30px"></asp:Label>
<asp:Label ID="lblPergunta5" runat="server" Height="30px"></asp:Label>
<asp:Label ID="lblPergunta6" runat="server" Height="30px"></asp:Label>
<asp:Label ID="lblPergunta7" runat="server" Height="30px"></asp:Label>
<asp:Label ID="lblPergunta8" runat="server" Height="30px"></asp:Label>
<asp:Label ID="lblPergunta9" runat="server" Height="30px"></asp:Label>
<asp:Label ID="lblPergunta10" runat="server" Height="30px"></asp:Label>
</td>
</tr>
<tr>
<td >
</td>
<td>
<asp:Button ID="btnT" CssClass="btn btn-xs" runat="server" Text="Encerrar" /></td>
</tr>
</table>
</asp:Panel>
</div>
<asp:ModalPopupExtender ID="ModalPopupExtenderLogin" runat="server"
TargetControlID="btnok"
PopupControlID="Panel1"
BackgroundCssClass="modalBackground"
DropShadow="true"
CancelControlID="btnT" />
</div>
</div>
</asp:Content>
Code C#:
namespace dygaquiz
{
public partial class Questionario : System.Web.UI.Page
{
int count, rbl1, rbl2, rbl3, rbl4, rbl5, rbl6, rbl7, rbl8, rbl9, rbl10;
Crud crud = new Crud();
static List<QuestionarioDados> questio = new List<QuestionarioDados>();
public class QuestionarioDados
{
public int Id { get; set; }
public string Pergunta { get; set; }
public int certa { get; set; }
public DataSet Ds { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnok_click(object sender, EventArgs e)
{
ModalPopupExtenderLogin.Show();
}
protected void btnCarregarClick(object sender, EventArgs e)
{
CarregarQuestionario(DropDownList1.SelectedIndex);
div.Visible = true;
}
protected void btnCorrigir_Click(object sender, EventArgs e)
{
count = 0;
Corrigir();
btnCorrigir.Visible = false;
}
public void Corrigir()
{
if (RadioButtonList1.SelectedItem != null)
{
if (questio[0].certa.ToString() == rbl1.ToString())
{
RadioButtonList1.SelectedItem.Attributes.Add("style", "background-color:green");
count++;
}
else
{
RadioButtonList1.SelectedItem.Attributes.Add("style", "background-color:red");
}
}
if (RadioButtonList2.SelectedItem != null)
{
if (questio[1].certa.ToString() == rbl2.ToString())
{
RadioButtonList2.SelectedItem.Attributes.Add("style", "background-color:green");
count++;
}
else
{
RadioButtonList2.SelectedItem.Attributes.Add("style", "background-color:red");
}
}
if (RadioButtonList3.SelectedItem != null)
{
if (questio[2].certa.ToString() == rbl3.ToString())
{
RadioButtonList3.SelectedItem.Attributes.Add("style", "background-color:green");
count++;
}
else
{
RadioButtonList3.SelectedItem.Attributes.Add("style", "background-color:red");
}
}
if (RadioButtonList4.SelectedItem != null)
{
if (questio[3].certa.ToString() == rbl4.ToString())
{
RadioButtonList4.SelectedItem.Attributes.Add("style", "background-color:green");
count++;
}
else
{
RadioButtonList4.SelectedItem.Attributes.Add("style", "background-color:red");
}
}
if (RadioButtonList5.SelectedItem != null)
{
if (questio[4].certa.ToString() == rbl5.ToString())
{
RadioButtonList5.SelectedItem.Attributes.Add("style", "background-color:green");
count++;
}
else
{
RadioButtonList5.SelectedItem.Attributes.Add("style", "background-color:red");
}
}
if (RadioButtonList6.SelectedItem != null)
{
if (questio[5].certa.ToString() == rbl6.ToString())
{
RadioButtonList6.SelectedItem.Attributes.Add("style", "background-color:green");
count++;
}
else
{
RadioButtonList6.SelectedItem.Attributes.Add("style", "background-color:red");
}
}
if (RadioButtonList7.SelectedItem != null)
{
if (questio[6].certa.ToString() == rbl7.ToString())
{
RadioButtonList7.SelectedItem.Attributes.Add("style", "background-color:green");
count++;
}
else
{
RadioButtonList7.SelectedItem.Attributes.Add("style", "background-color:red");
}
}
if (RadioButtonList8.SelectedItem != null)
{
if (questio[7].certa.ToString() == rbl8.ToString())
{
RadioButtonList8.SelectedItem.Attributes.Add("style", "background-color:green");
count++;
}
else
{
RadioButtonList8.SelectedItem.Attributes.Add("style", "background-color:red");
}
}
if (RadioButtonList9.SelectedItem != null)
{
if (questio[8].certa.ToString() == rbl9.ToString())
{
RadioButtonList9.SelectedItem.Attributes.Add("style", "background-color:green");
count++;
}
else
{
RadioButtonList9.SelectedItem.Attributes.Add("style", "background-color:red");
}
}
if (RadioButtonList10.SelectedItem != null)
{
if (questio[9].certa.ToString() == rbl10.ToString())
{
RadioButtonList10.SelectedItem.Attributes.Add("style", "background-color:green");
count++;
}
else
{
RadioButtonList10.SelectedItem.Attributes.Add("style", "background-color:red");
}
}
if (count == 1)
{
lbll.Text = "Acertou " + count.ToString() + " questão.";
}
if (count == 0)
{
lbll.Text = "Não acertou questão alguma.";
}
if (count > 1)
{
lbll.Text = "Acertou " + count.ToString() + " questões.";
}
btnCorrigir.Visible = false;
btnok.Visible = true;
Linkbtn.Visible = true;
lblll.Visible = true;
lblPergunta1.Text = "Questão 1: " + ((int)questio[0].certa + 1);
lblPergunta2.Text = "Questão 2: " + ((int)questio[1].certa + 1);
lblPergunta3.Text = "Questão 3: " + ((int)questio[2].certa + 1);
lblPergunta4.Text = "Questão 4: " + ((int)questio[3].certa + 1);
lblPergunta5.Text = "Questão 5: " + ((int)questio[4].certa + 1);
lblPergunta6.Text = "Questão 6: " + ((int)questio[5].certa + 1);
lblPergunta7.Text = "Questão 7: " + ((int)questio[6].certa + 1);
lblPergunta8.Text = "Questão 8: " + ((int)questio[7].certa + 1);
lblPergunta9.Text = "Questão 9: " + ((int)questio[8].certa + 1);
lblPergunta10.Text = "Questão 10: " + ((int)questio[9].certa + 1);
questio.Clear();
}
protected void rdbList1_SelectedIndexChanged(object sender, EventArgs e)
{
rbl1 = RadioButtonList1.SelectedIndex;
}
protected void rdbList2_SelectedIndexChanged(object sender, EventArgs e)
{
//pega o index da lista de radio
rbl2 = RadioButtonList2.SelectedIndex;
}
protected void rdbList3_SelectedIndexChanged(object sender, EventArgs e)
{
//pega o index da lista de radio
rbl3 = RadioButtonList3.SelectedIndex;
}
protected void rdbList4_SelectedIndexChanged(object sender, EventArgs e)
{
//pega o index da lista de radio
rbl4 = RadioButtonList4.SelectedIndex;
}
protected void rdbList5_SelectedIndexChanged(object sender, EventArgs e)
{
//pega o index da lista de radio
rbl5 = RadioButtonList5.SelectedIndex;
}
protected void rdbList6_SelectedIndexChanged(object sender, EventArgs e)
{
//pega o index da lista de radio
rbl6 = RadioButtonList6.SelectedIndex;
}
protected void rdbList7_SelectedIndexChanged(object sender, EventArgs e)
{
//pega o index da lista de radio
rbl7 = RadioButtonList7.SelectedIndex;
}
protected void rdbList8_SelectedIndexChanged(object sender, EventArgs e)
{
//pega o index da lista de radio
rbl8 = RadioButtonList8.SelectedIndex;
}
protected void rdbList9_SelectedIndexChanged(object sender, EventArgs e)
{
//pega o index da lista de radio
rbl9 = RadioButtonList9.SelectedIndex;
}
protected void rdbList10_SelectedIndexChanged(object sender, EventArgs e)
{
//pega o index da lista de radio
rbl10 = RadioButtonList10.SelectedIndex;
}
public void CarregarQuestionario(int a)
{
Label1.Visible = true;
Label2.Visible = true;
Label3.Visible = true;
Label4.Visible = true;
Label5.Visible = true;
Label6.Visible = true;
Label7.Visible = true;
Label8.Visible = true;
Label9.Visible = true;
Label10.Visible = true;
btnCorrigir.Visible = true;
lbll.Visible = true;
int x = 0;
if (crud.Read(a) != null)
{
foreach (DataRow row in crud.Read(a).Rows)
{
int id = (int)row["Id"];
string pergunta = row["pergunta"].ToString();
int certa = (int)row["certa"];
x++;
if (crud.Read2(id) != null)
{
DataSet ds = new DataSet(); ds.Tables.Add(crud.Read2(id));
questio.Add(new QuestionarioDados() { Ds = ds, Id = id, Pergunta = pergunta, certa = certa });
}
else
questio.Add(new QuestionarioDados() { Id = id, Pergunta = pergunta, certa = certa });
}
if (questio[0] != null)
{
Label1.Text = questio[0].Pergunta;
RadioButtonList1.DataSource = questio[0].Ds;
RadioButtonList1.DataTextField = "Resposta";
RadioButtonList1.DataBind();
}
if (questio[1] != null)
{
Label2.Text = questio[1].Pergunta;
RadioButtonList2.DataSource = questio[1].Ds;
RadioButtonList2.DataTextField = "Resposta";
RadioButtonList2.DataBind();
}
if (questio[2] != null)
{
Label3.Text = questio[2].Pergunta;
RadioButtonList3.DataSource = questio[2].Ds;
RadioButtonList3.DataTextField = "Resposta";
RadioButtonList3.DataBind();
}
if (questio[3] != null)
{
Label4.Text = questio[3].Pergunta;
RadioButtonList4.DataSource = questio[3].Ds;
RadioButtonList4.DataTextField = "Resposta";
RadioButtonList4.DataBind();
}
if (questio[4] != null)
{
Label5.Text = questio[4].Pergunta;
RadioButtonList5.DataSource = questio[4].Ds;
RadioButtonList5.DataTextField = "Resposta";
RadioButtonList5.DataBind();
}
if (questio[5] != null)
{
Label6.Text = questio[5].Pergunta;
RadioButtonList6.DataSource = questio[5].Ds;
RadioButtonList6.DataTextField = "Resposta";
RadioButtonList6.DataBind();
}
if (questio[6] != null)
{
Label7.Text = questio[6].Pergunta;
RadioButtonList7.DataSource = questio[6].Ds;
RadioButtonList7.DataTextField = "Resposta";
RadioButtonList7.DataBind();
}
if (questio[7] != null)
{
Label8.Text = questio[7].Pergunta;
RadioButtonList8.DataSource = questio[7].Ds;
RadioButtonList8.DataTextField = "Resposta";
RadioButtonList8.DataBind();
}
if (questio[8] != null)
{
Label9.Text = questio[8].Pergunta;
RadioButtonList9.DataSource = questio[8].Ds;
RadioButtonList9.DataTextField = "Resposta";
RadioButtonList9.DataBind();
}
if (questio[9] != null)
{
Label10.Text = questio[9].Pergunta;
RadioButtonList10.DataSource = questio[9].Ds;
RadioButtonList10.DataTextField = "Resposta";
RadioButtonList10.DataBind();
}
}
}
}
}
That’s exactly what it was. Thank you very much!
– Dyganar Campos