You must Sign In to post a response.
  • Category: ASP.NET

    How to keep on changing time in lable control and stop after processing logic in C# web application

    I want to show time taken my function/process in C#.When I click on button show,I want show time in label as 0,and keep on changing like1,2,3,4,5.In button click event writing/processing/executing query ,when that process over I want stop time.How to do that?
  • #765899
    you can try bellow code ...
    Call this java script function on OnClientClick of button which sets the time on label "lblTime"

    <script type="text/javascript">
    function showtime() {
    setInterval(setTime, 1000);
    var lbl = document.getElementById('<%= lblTime.ClientID %>');
    var i = 0;
    function setTime() {
    lbl.innerHTML = i + ' Seconds';

    protected void Button1_Click(object sender, EventArgs e)
    System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
    //System.Threading.Thread.Sleep(3000); //sleeps for 3 seconds
    // Your code..
    lblTime.Text = watch.Elapsed.Seconds + " Seconds";


Sign In to post your comments