Friday, May 6, 2011

Time Reduced Using Timer Control


using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Timer1_Tick(object sender, EventArgs e)
    {
        UpdatePanel1.Visible = true;
        TimeSpan time1 = new TimeSpan();
        TimeSpan ts=new TimeSpan(00,00,00);
        if (i == 1)
        {
            time1 = (DateTime)Session["time"] - System.DateTime.Now;
           
                if (time1.Minutes < 10)
                {
                    lblmin.Text = "0" + time1.Minutes.ToString() + ":";
                }
                else
                {
                    lblmin.Text = time1.Minutes.ToString() + ":";
                }
                if (time1.Seconds < 10)
                {
                    lblsec.Text = "0" + time1.Seconds.ToString();
                }
                else
                {
                    lblsec.Text = time1.Seconds.ToString();
                }
            }
       
    }

    protected void btnStart_Click(object sender, EventArgs e)
    {
        UpdatePanel1.Visible = true;
        Session["time"] = DateTime.Now.AddMinutes(1);
        i++;
    }


}

Monday, May 2, 2011

Another Way of Time Displaying in asp.net using javascript


<script type="text/javascript">
    function ShowTime() {
        var dt = new Date();
        document.getElementById("<%= TextBox1.ClientID %>").value = dt.toLocaleTimeString();
        window.setTimeout("ShowTime()", 1000);
    }  
</script>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<script type="text/javascript">
    // a startup script to put everything in motion
    window.setTimeout("ShowTime()", 1000);
</script>

Time Displaying In Asp.net 3.5 Using JavaScript


 <script type="text/javascript">
                        i = 1;

                        function tim() {
                            d = new Date();
                            h = d.getHours();
                            m = d.getMinutes();
                            s = d.getSeconds();
                            if (h < 10) {
                                h = "0" + h;
                            }
                            if (m < 10) {
                                m = "0" + m;
                            }
                            if (s < 10) {
                                s = "0" + s;
                            }
                            t = "" + h + ":" + m + ":" + s;
                            document.aspnetForm.htmltxt.value = t;
                        }

                        setInterval("tim()", 100);
</script>