Click here to Skip to main content
15,897,519 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have repeater that show questions and 4 option of answer , i want to show correct answer after one minute

What I have tried:

HTML
    <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:Label ID="lblTime" runat="server" />
        <br />
        <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
            <ItemTemplate >
                <div class="panel-heading">
                    
                    <div class="panel-title btn-label q-border">
                          <h3 class="Golden-color"><span class="label label-success" style="margin-left:10px;" id="qid"><%# Eval("Category") %></span><%# Eval("Question") %></h3>
                    </div>
                    <h2 id="counter" class="Golden-color"></h2>
                     
                </div>
                <div class="panel-body card ">

          <div class="quiz" id="quiz" data-toggle="buttons">
           <label class="element-animation1 btn btn-lg btn-transparent btn-block"><span class="btn-label"></span> <input type="radio" name="q_answer" value="2">
               <%# Eval("OptionB") %>
           </label>
           <label class="element-animation3 btn btn-lg btn-transparent btn-block"><span class="btn-label">^__i class="glyphicon">ج</span> <input type="radio" name="q_answer" value="3">
               <%# Eval("OptionC") %>
           </label>
           <label class="element-animation4 btn btn-lg btn-transparent btn-block"><span class="btn-label">^__i class="glyphicon">د</span> <input type="radio" name="q_answer" value="4">
                <%# Eval("OptionD") %>
           </label>
              <asp:Label ID="LblCorrectAnswer" runat="server" Visible="false" Text='<%#Eval("CorrectAnswer")%>' CssClass="label label-success"></asp:Label>
       </div>
   </div>
            </ItemTemplate>
            
        </asp:Repeater>
       
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>"
            SelectCommand="SELECT TOP 1 * FROM Questions ORDER BY NEWID()"></asp:SqlDataSource>
        <asp:Timer ID="Timer1" runat="server" OnTick="TimerTick" Interval="10000" Enabled ="true"  />
    </ContentTemplate>
</asp:UpdatePanel>


VB
Protected Sub TimerTick(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
    If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
        Dim lbl As Label = TryCast(e.Item.FindControl("LblCorrectAnswer"), Label)
        lbl.Visible = True
    End If
    Timer1.Enabled = False
End Sub
Posted
Updated 21-Jul-19 0:22am
v2

1 solution

You're going to have to rework this. You don't seem to realize that all of the VB.NET code you wrote runs on the server-side only. ASP.NET code generates HTML to send to the client.

That Time you're using will NOT work. It's running entirely on the server. That code will not modify the content of any label control on the client side.

If you're going to modify the content of a label on the client, you're going to have to write javascript code that runs on the client to modify the content of the HTML that the "label control" becomes client-side.
 
Share this answer
 
Comments
Member 11057552 20-Jul-19 12:21pm    
Thank you, Dave Kreskowiak
How to call javascript code at timer tick ?
Dave Kreskowiak 20-Jul-19 19:28pm    
You don't. You don';t use a timer in your ASP.NET code AT ALL.

The "timer" has to be coded in the javascript and the function it calls should update the label with whatever you want.

https://www.w3schools.com/js/js_timing.asp

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900