Results 1 to 7 of 7

Thread: [RESOLVED] counter

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Resolved [RESOLVED] counter

    in desktop app, this is the code
    but in web app it doesnt work, why?
    tnx in advance

    Code:
        protected void Page_Load(object sender, EventArgs e)
        {
            t = 5;
            Label1.Text = DateTime.Now.ToString();
            Label2.Text = DateTime.Now.ToString();
        }
        protected void Timer1_Tick(object sender, EventArgs e)
        {
            Label2.Text = DateTime.Now.ToString();
           
            Label3.Text = t.ToString();
            t = t - 1;
               
                if (t == 0)
                {
                    Label3.Text = "gdfgdg";
                    t = 5;
                }
        }
    *****************
    VB6,PHP,VS 2005

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: counter

    It doesn't make sense to use a server side timer in an ASP.NET application. The ASP.NET application will just execute the codebehind and output the page. The Timer Tick event is therefore redundant.

    You will need to translate the code you want done in the timer tick event to javascript which runs on the client side.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: counter

    i found the solution... pls see below.
    hope in some questions for the newbies like me would help in the future

    Code:
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["TestVal"] == null)
            {
                Session["TestVal"] = 5;
            }
            Label1.Text = DateTime.Now.ToString();
            Label2.Text = DateTime.Now.ToString();
        }
        protected void Timer1_Tick(object sender, EventArgs e)
        {
    
            Label2.Text = DateTime.Now.ToString();
            Session["TestVal"] = Convert.ToString(Convert.ToInt32(Session["TestVal"]) - 1);
            Label3.Text = (string)Session["TestVal"];
            if (Convert.ToInt32(Label3.Text) == 0)
            {
                Label3.Text = "gdfgdg";
                Session["TestVal"] = 5;
            }
        }
    *****************
    VB6,PHP,VS 2005

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: counter

    ***** RE-SEND

    Code:
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Convert.ToInt32(Session["TestVal"]) == 0)
            {
                Session["TestVal"] = 5;
            }
    
            Label1.Text = DateTime.Now.ToString();
            Label2.Text = DateTime.Now.ToString();
        }
        protected void Timer1_Tick(object sender, EventArgs e)
        {
    
            Label2.Text = DateTime.Now.ToString();
            Session["TestVal"] = Convert.ToString(Convert.ToInt32(Session["TestVal"]) - 1);
            Label3.Text = (string)Session["TestVal"];
            if (Convert.ToInt32(Label3.Text) == 0)
            {
                Label3.Text = "5";
                Session["TestVal"] = 5;
            }
        }
    *****************
    VB6,PHP,VS 2005

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: counter

    Again, it won't make a lot of sense, because you're not going to be seeing the changes as the label's text gets updated by the changing values, unless this is in an UpdatePanel in which case it's usually best to divulge such information when asking a question.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: counter

    the label is updating and it is inside the updatePanel object
    *****************
    VB6,PHP,VS 2005

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: counter

    Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width