Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

i have asp.net website in c#...

i have a web user control, in which i have a timer where i'm dealing with the session time out & this timer is with interval of 1000 milliseconds.

and i have placed this timerUserCtrl on my masterpage.

but on every second the page is getting load, which is degrading the performance of the page, means, its not allowing to do anything on the page, as soon as the user want to select from list its get refresh.....

timeruserctrl
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Timer ID="TimerSession" runat="server" ontick="TimerSession_Tick">
                </asp:Timer>
                <asp:Panel ID="PanelSession" Visible="false" runat="server">
                <table class="addgrid">
                <tr style="background-image: removed('images/Background.png'); height: 30px; color: Black;">
                <td>
                Session About Expire
                </td>
                </tr>
                <tr>
                <td>
                
                    <asp:Label ID="lbl" runat="server"></asp:Label><br />
                <center>
                Your Session is about to Expire, Do you want to Continue?
                </center><br /></td>
                </tr>
                <tr>
                <td>
                <div style="padding-removed 200px;">
                    <asp:Button ID="btnContinue" runat="server" Text="Continue"  CssClass="WhiteBlackBtn"
                        onclick="btnContinue_Click" />  
                    <asp:Button ID="btnCancel" runat="server" CssClass="WhiteBlackBtn" Text="Cancel" 
                        onclick="btnCancel_Click" />
                        </div>
                </td>
                </tr>
                </table>
                </asp:Panel>
            </ContentTemplate>
            <Triggers>
            <asp:AsyncPostBackTrigger ControlID="TimerSession" />
            <asp:AsyncPostBackTrigger ControlID="btnContinue" />
            </Triggers>
            </asp:UpdatePanel>


timeuserctrl.cs
protected void Page_Load(object sender, EventArgs e)
    {
        TimerSession.Enabled = true;
        TimerSession.Interval = 1000;
    }


    protected void TimerSession_Tick(object sender, EventArgs e)
    {
        if (Session["timeout"] != null)
        {
            if (0 > DateTime.Compare(DateTime.Now, DateTime.Parse(Session["timeout"].ToString())))
            {
                string mins = ((Int32)DateTime.Parse(Session["timeout"].ToString()).Subtract(DateTime.Now).TotalMinutes).ToString();
                if (mins == "1")
                {
                    PanelSession.Visible = true;
                    TimerSession.Enabled = false;
                }
            }
        }
        else
        {
            Response.Redirect("logout.aspx");
        }
    }


Masterpage.master
<uc1:SessionTimeoutCtrl ID="SessionTimeoutCtrl1"  runat="server" />
       <asp:ContentPlaceHolder id="CntPLH_MainContent" runat="server">

       </asp:ContentPlaceHolder>


can anyone please help me, how can i stop this page getting refresh on every second.

Thanks
Posted
Updated 9-Nov-14 19:00pm
v2

1 solution

so why 1000 milliseconds ? you set up that value, not us - do you really think a user can do something on a page in one second ? I think not

so, why not simple increase the value to something reasonable ? 3 minutes (3 * 60 * 1000) or even 5 minutes ?

I would combine the timeout timer with some sort of 'reset', so if the user is entering data or doing things, you're resetting the idle timer - yeah, its hard, but more correct
 
Share this answer
 
Comments
abdul subhan mohammed 9-Nov-14 17:23pm    
Not a better solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900