0

I have this hidden button that is linked to a function I would like to trigger automatically on the web page once the session has been timed out:

Button code:

<asp:Button runat="server" id ="btnHdn"  Style="display: none" OnClick="Button1_Click"/>

Timeout session trigger:

setTimeout(function ()
{
  document.getElementById("btnHdn").click;
}, timeout);

The code behind I would like to call (.cs):

protected void Button1_Click(object sender, EventArgs e)
{
    RedirectToHomePage();
}

protected void RedirectToHomePage()
{
    try
    {
        string whichCountry = ConfigurationManager.AppSettings["country"].ToString();
        string isFromGMAL = ConfigurationManager.AppSettings["GMAL"].ToString();
        string urlStr = "LanguageSelection.aspx";
        if (whichCountry.ToLower() == "sg")
        {
            urlStr = "LandingPage.aspx";
        }
        else if (whichCountry.ToLower() == "nl")
        {
            urlStr = "LandingPagexxxx.aspx";
        }
    }
    catch (System.Exception ex)
    {
    }
}

Apparently, the code does not seem to be working. Once the session has reached zero, nothing happened and the timer will keep continue on counting.

Would you guys please identify what is wrong with the code?

FCin
  • 3,804
  • 4
  • 20
  • 49
  • Try Abdullah's answer and let us know! – Prashant Pimpale Dec 18 '18 at 05:52
  • Possible duplicate of [How to trigger a method when session ends in c#](https://stackoverflow.com/questions/20659498/how-to-trigger-a-method-when-session-ends-in-c-sharp) – Prashant Pimpale Dec 18 '18 at 05:53
  • 1
    Hi @PrashantPimpale, the solution given by Umair below is working. The article you have suggested there has a different scenario to mine. Anyways, the problem has resolved. Thank you. – ChrisQuirk Dec 18 '18 at 23:21

1 Answers1

0

You just need to change little bit on JavaScript code cause btnHdn button ClientId is change on client side so use it like below and .click is a method so add brackets on it like .click()

setTimeout(function () {
   document.getElementById("<%=btnHdn.ClientID%>").click();
}, timeout);
Umair Anwaar
  • 1,130
  • 9
  • 27