working on creating a web based revision resource and i am trying to create a multiple choice quiz in c# with asp.net. I have created it and got it working but it is very long and was wondering if anyone had an idea of how i could make the code more compact, also when it prints the final score it appears above my nav bar on my website by i have no idea why.
in addition, the answers can be changed and the submit button just re clicked, i cannot for the love of anything find anything on how to stop this.
I am extremely new to everything and am trying my best. if someone could point me in the right direction or suggest something that might help that would be awesome.
Thanks
I appologise for the length of the code:
<asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Body" runat="server">
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
RepeatDirection="Horizontal" RepeatLayout="Table">
<asp:ListItem Text="*Answer 1*" Value="Incorrect 1" />
<asp:ListItem Text="*Answer 2*" Value="Correct" />
<asp:ListItem Text="*Answer 3*" Value="I" />
<asp:ListItem Text="*Answer 4*" Value="4" />
</asp:RadioButtonList>
<asp:RadioButtonList ID="RadioButtonList2" runat="server"
RepeatDirection="Horizontal" RepeatLayout="Table">
<asp:ListItem Text="*Answer 1*" Value="Incorrect 1" />
<asp:ListItem Text="*Answer 2*" Value="Correct" />
<asp:ListItem Text="*Answer 3*" Value="I" />
<asp:ListItem Text="*Answer 4*" Value="4" />
</asp:RadioButtonList>
<asp:RadioButtonList ID="RadioButtonList3" runat="server"
RepeatDirection="Horizontal" RepeatLayout="Table">
<asp:ListItem Text="*Answer 1*" Value="Incorrect 1" />
<asp:ListItem Text="*Answer 2*" Value="Correct" />
<asp:ListItem Text="*Answer 3*" Value="I" />
<asp:ListItem Text="*Answer 4*" Value="4" />
</asp:RadioButtonList>
<asp:RadioButtonList ID="RadioButtonList4" runat="server"
RepeatDirection="Horizontal" RepeatLayout="Table">
<asp:ListItem Text="*Answer 1*" Value="Incorrect 1" />
<asp:ListItem Text="*Answer 2*" Value="Correct" />
<asp:ListItem Text="*Answer 3*" Value="I" />
<asp:ListItem Text="*Answer 4*" Value="4" />
</asp:RadioButtonList>
<asp:RadioButtonList ID="RadioButtonList5" runat="server"
RepeatDirection="Horizontal" RepeatLayout="Table">
<asp:ListItem Text="*Answer 1*" Value="Incorrect 1" />
<asp:ListItem Text="*Answer 2*" Value="Correct" />
<asp:ListItem Text="*Answer 3*" Value="I" />
<asp:ListItem Text="*Answer 4*" Value="4" />
</asp:RadioButtonList>
<asp:RadioButtonList ID="RadioButtonList6" runat="server"
RepeatDirection="Horizontal" RepeatLayout="Table">
<asp:ListItem Text="*Answer 1*" Value="Incorrect 1" />
<asp:ListItem Text="*Answer 2*" Value="Correct" />
<asp:ListItem Text="*Answer 3*" Value="I" />
<asp:ListItem Text="*Answer 4*" Value="4" />
</asp:RadioButtonList>
<asp:RadioButtonList ID="RadioButtonList7" runat="server"
RepeatDirection="Horizontal" RepeatLayout="Table">
<asp:ListItem Text="*Answer 1*" Value="Incorrect 1" />
<asp:ListItem Text="*Answer 2*" Value="Correct" />
<asp:ListItem Text="*Answer 3*" Value="I" />
<asp:ListItem Text="*Answer 4*" Value="4" />
</asp:RadioButtonList>
<asp:RadioButtonList ID="RadioButtonList8" runat="server"
RepeatDirection="Horizontal" RepeatLayout="Table">
<asp:ListItem Text="*Answer 1*" Value="Incorrect 1" />
<asp:ListItem Text="*Answer 2*" Value="Correct" />
<asp:ListItem Text="*Answer 3*" Value="I" />
<asp:ListItem Text="*Answer 4*" Value="4" />
</asp:RadioButtonList>
<asp:RadioButtonList ID="RadioButtonList9" runat="server"
RepeatDirection="Horizontal" RepeatLayout="Table">
<asp:ListItem Text="*Answer 1*" Value="Incorrect 1" />
<asp:ListItem Text="*Answer 2*" Value="Correct" />
<asp:ListItem Text="*Answer 3*" Value="I" />
<asp:ListItem Text="*Answer 4*" Value="4" />
</asp:RadioButtonList>
<asp:RadioButtonList ID="RadioButtonList10" runat="server"
RepeatDirection="Horizontal" RepeatLayout="Table">
<asp:ListItem Text="*Answer 1*" Value="Incorrect 1" />
<asp:ListItem Text="*Answer 2*" Value="Correct" />
<asp:ListItem Text="*Answer 3*" Value="I" />
<asp:ListItem Text="*Answer 4*" Value="4" />
</asp:RadioButtonList>
<asp:Button ID="Button1" runat="server" Text="Submit Final Answers" OnClick="Submit_Click" />
<script runat="server">
protected void Submit_Click(object sender, EventArgs e)
{
int Score = 0;
string selectedValue1 = RadioButtonList1.SelectedValue;
if (selectedValue1 == "Correct")
{
Score++;
}
string selectedValue2 = RadioButtonList2.SelectedValue;
if (selectedValue2 == "Correct")
{
Score++;
}
string selectedValue3 = RadioButtonList3.SelectedValue;
if (selectedValue3 == "Correct")
{
Score++;
}
string selectedValue4 = RadioButtonList4.SelectedValue;
if (selectedValue4 == "Correct")
{
Score++;
}
string selectedValue5 = RadioButtonList5.SelectedValue;
if (selectedValue5 == "Correct")
{
Score++;
}
string selectedValue6 = RadioButtonList6.SelectedValue;
if (selectedValue6 == "Correct")
{
Score++;
}
string selectedValue7 = RadioButtonList7.SelectedValue;
if (selectedValue7 == "Correct")
{
Score++;
}
string selectedValue8 = RadioButtonList8.SelectedValue;
if (selectedValue8 == "Correct")
{
Score++;
}
string selectedValue9 = RadioButtonList9.SelectedValue;
if (selectedValue9 == "Correct")
{
Score++;
}
string selectedValue10 = RadioButtonList10.SelectedValue;
if (selectedValue10 == "Correct")
{
Score++;
}
Response.Write(Score);
}
</script>
</asp:Content>