Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6659931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:05:30+00:00 2026-05-26T02:05:30+00:00

I need to be able to trigger events when a user clicks on a

  • 0

I need to be able to trigger events when a user clicks on a radio button that is generated within an control on my page.

I’ve added an OnSelectedIndexChanged handler to the RadioButtonList and created a function in my code behind that should handle the selection of the RadioButtonList’s ListItems, but I don’t know how to pass a value to that function.
Here’s my code:

<asp:Repeater runat="server" ID="rptQuestions">
    <HeaderTemplate><table width="100%"></HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td colspan="2"><%# Container.DataItem("QuestionText")%></td>
        </tr>
        <tr>
            <td>
                <asp:RadioButtonList runat="server" ID="rblAnswerSelection" RepeatDirection="Horizontal" AutoPostBack="true" OnSelectedIndexChanged="CheckAnswer">
                    <asp:ListItem Text="True" Value="1"></asp:ListItem>
                    <asp:ListItem Text="False" Value="0"></asp:ListItem>
                </asp:RadioButtonList>
                <asp:Label runat="server" ID="lblCorrectAnswer" Text="<%#Container.DataItem("CorrectAnswer") %>"></asp:Label>
            </td>
            <td><asp:Label runat="server" ID="lblResult"></asp:Label></td>
        </tr>
    </ItemTemplate>
    <FooterTemplate></table></FooterTemplate>
</asp:Repeater>

Private Function CheckAnswer(ByVal SelectedAnswer As Integer) As Boolean
    Select Case SelectedAnswer
        Case 1 ' User answered True
            If lblCorrectAnswer.Text = "True" Then
                Return True
            Else
                Return False
            End If
        Case 0 ' User answered False
            If lblCorrectAnswer.Text = "False" Then
                Return True
            Else
                Return False
            End If
    End Select
End Function

The idea is that the user is to be informed whether or not their selected answer was correct. The value of the CheckAnswer function would determine a “CORRECT” or “INCORRECT” message displaying on lblResult. If there’s a way to do this without a PostBack, then that would be ideal.

Any suggestions will be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:05:31+00:00Added an answer on May 26, 2026 at 2:05 am

    Here’s brief outline of client side solution (w/o post-back). Use html radio-buttons along with a hidden field to store the correct answer. Attach click event handlers on radio-buttons to match the value with the value from hidden field.

    Repeater Mark-up:

        <tr>
            <td colspan="2"><%# Container.DataItem("QuestionText")%></td>
        </tr>
        <tr>
            <td class="answerContainer">
                <input type="radio" class="option" name='answer_<%# Container.ItemIndex %>' value="1">True
                <input type="radio" class="option" name='answer_<%# Container.ItemIndex %>' value="0">False                
                <input type="hidden" id="correct_answer" value='<%#Container.DataItem("CorrectAnswer") %>' />
            </td>
            <td>
                <span class="result" />
            </td>
        </tr>
    

    Java-script (using jquery):

    $(document).ready(function() {
    
      $('td.answerContainer .option').click(function() {   
          var opt = $(this);
          var correctAns = opt.next('#correct_answer');
          var result = (opt.val() == correctAns.val()) ? "Correct" : "Incorrect";
          opt.parent().next('td').find('.result').html(result);
      });
    
    });
    

    Disclaimer: untested code

    Note that radio button names are suffixed with the item index so that on the server side, you can read the user’s answers by looking into the request (for example, value of Request["answer_1"] should tell user selected answer for second question -> “1” : True, “0”: False and empty string: no selection).

    The obvious disadvantage is that correct answer is stored in the html and so it will be simpler to cheat the system. Solution can be to make ajax call to the server to check if the answer is correct or not – this will need creating salted time-bound pseudo-random tokens to identify questions (otherwise user can make same ajax calls to get answers).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a flash based video player that is able to trigger events I
I need to be able to trigger a event whenever an object is added
I need to be able to get at the full URL of the page
I need to be able to get a list of the groups a user
I need a way to trigger events on remote processes over the wire and
I have a custom control and I want the user to be able to
I developed a user control that displays a list of products and it works
I have a gridview that contains data. I want the user to be able
Users of the website need to able to store images in their area ,
Need to be able to pull Magento products into an external template. Need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.