Time limit validation (C#) : Date Time « Development « ASP.Net

ASP.Net
1. ADO.net Database
2. Asp Control
3. Collections
4. Components
5. Data Binding
6. Development
7. HTML Control
8. Mobile Control
9. Page
10. Request
11. Response
12. Server
13. Session Cookie
14. User Control and Master Page
15. Validation by Control
16. Validation by Function
17. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.Net » Development » Date Time 
Time limit validation (C#)

<%@ Page Language="C#" %>

<script runat="server">

    void Page_Load()
    {
        if (!Page.IsPostBack)
            ResetStartTime();
    }
    
    void btnAgain_Click(Object sender, EventArgs e)
    {
        ResetStartTime();
    }
    
    void ResetStartTime()
    {
        Session["StartTime"= DateTime.Now;
    }
    
    
    void valAnswer_ServerValidate(Object source, ServerValidateEventArgs args)
    {
        DateTime startTime = (DateTime)Session["StartTime"];
        if (startTime.AddSeconds(5> DateTime.Now)
            args.IsValid = true;
        else
            args.IsValid = false;
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Timed Test</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    <p>
    You have seconds to answer the following question:
    </p>
    
    <asp:Label
        id="lblQuestion"
        Text="What was Aristotle's first name?"
        AssociatedControlID="txtAnswer"
        Runat="server" />
    <br />
    <asp:TextBox
        id="txtAnswer"
        Runat="server" />    
    <asp:CustomValidator
        id="valAnswer"
        Text="(You answered too slowly!)"
        OnServerValidate="valAnswer_ServerValidate"
        Runat="server"  />
    
    <br /><br />
    
    <asp:Button
        id="btnSubmit"
        Text="Submit"
        Runat="server" />
    
    <asp:Button
        id="btnAgain"
        Text="Try Again!"
        CausesValidation="false"
        OnClick="btnAgain_Click"
        Runat="server" />
    
    </div>
    </form>
</body>
</html>

           
       
Related examples in the same category
1. Year() function (VB.net)
2. Get Today date (VB.net)
3. Get Time Of a Day (VB.net)
4. DateTime constructor: no parameters (VB.net)
5. DateTime constructor: year, month, day (VB.net)
6. DateTime constructor: year, month, day, hour, minute, second (VB.net)
7. DateTime constructor: milli-second (VB.net)
8. Assign Date and Integer value to asp:textbox without converting (VB.net)
9. Get Hour, Second and Minute from Current time (VB.net)
10. Assign date in form of '#3/6/2003#' to asp:Label (VB.net)
11. Convert Current date to Long Time String and set to asp:Label (VB.net)
12. Convert Current date to Long Date String and set to asp:Label (VB.net)
13. Convert Current date to Short Time String and set to asp:Label (VB.net)
14. Convert Current date to Short Date String and set to asp:Label (VB.net)
15. new DateTime() (C#)
16. DateTime constructor: year, month, day (C#)
17. DateTime constructor: year, month, day, hour, minute, second (C#)
18. DateTime constructor: milli-seconds (C#)
19. Date Comparison (C#)
20. Convert text in asp textbox into Date (C#)
21. Date calculation: plus 7 days (C#)
ww_w__._j___a__v___a2___s___.___c___o___m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.