NANDAKUMAR THANGAVELU
NANDAKUMAR THANGAVELU

Reputation: 661

TimerTick event is not firing when hooked inside !IsPostBack

New to asp.net.

My motive is,

"User has to be taken to some page after a predefined set of the time interval. Session should not be used."

So, I thought to use Timer and inside the timer tick event, I can do a Server.Redirect. This timer is inside the user control page, which is common across all pages.

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            redirectTimer.Interval = 20000;
            redirectTimer.Tick += new EventHandler<EventArgs>(redirectTimer_Tick);                
        }
    }

    void redirectTimer_Tick(object sender, EventArgs e)
    {
        Server.Transfer("~/SomePageGoesHere.aspx");
    }

Case 2:

    protected void Page_Load(object sender, EventArgs e)
    {
            redirectTimer.Interval = 20000;
            redirectTimer.Tick += new EventHandler<EventArgs>(redirectTimer_Tick);                            
    }

    void redirectTimer_Tick(object sender, EventArgs e)
    {
        Server.Transfer("~/SomePageGoesHere.aspx");
    }

But in this case, it worked.

My question is,

  1. Whether "!IsPostBack" is having something to do with timer? (Case 1 and 2).

  2. Is there any better approach available other than this timer, session or cookies. etc?

Could someone share some input here?

Upvotes: 0

Views: 38

Answers (0)

Related Questions