locked
trigger postback from js RRS feed

  • Question

  • User1310055179 posted

    Hi,

    How can I trigger a postback of the 'Logout' image button by using javascript?

    This is the ASPX code:

    <asp:Panel ID="logoutPanel" runat="server" HorizontalAlign="Center">
                    <asp:ImageButton ID="Logout" runat="server" ImageUrl="~/Images/logout.png" Height="48px" ToolTip="Logout" onclick="pageRedirect" ClientIDMode="Static" OnClientClick="skm_LockScreen('skm_LockPane');"/><br />
                    <asp:Label ID="Label4" runat="server" Text="Logout" ForeColor="LightGray" ClientIDMode="Static" CssClass="sideMenu_labels"></asp:Label>
                </asp:Panel>

    I tried using the following code, but it didn't work:

    __doPostBack('''Logout');
    

    The JS function:

    var seconds = timeout / 1000;
                document.getElementsByName("secondsIdle").innerHTML = seconds;
                document.getElementsByName("seconds").innerHTML = seconds;
                setInterval(function () {
                    seconds--;
                    document.getElementById("seconds").innerHTML = seconds;
                    document.getElementById("secondsIdle").innerHTML = seconds;
                }, 1000);
                setTimeout(function () {
                    //Show Popup before 20 seconds of timeout.
                    $find("mpeTimeout").show();
                }, timeout - 20 * 1000);
                setTimeout(function () {
                    window.location = "login.aspx/?Error=2";//session timeout
                    __doPostBack('Logout''');
                }, timeout);

    The C# code:

    protected void pageRedirect(object sender, ImageClickEventArgs e)
            {
                string PostBackControlID = getPostBackControlName().ToString();//find the control which is responsible for the postback
                switch (PostBackControlID)
                {
                    ...
                    case "Logout":
                        FormsAuthentication.SignOut();
                        updateLastLogout(user, Session["Group"].ToString().Trim().ToLower());
                        Logic.ApplicLog.AddToLog(user, """""Logout");
                        FormsAuthentication.RedirectToLoginPage();
                        break;
                    ...
                }
            }

    The post back is triggered but the pageRedirect function doesn't fire at all.

    Wednesday, September 12, 2018 6:34 AM

Answers

  • User61956409 posted

    Hi qsoft_developer,

    The post back is triggered but the pageRedirect function doesn't fire at all.

    To solve the problem, you can do redirect in your code behind, like below.

    protected void pageRedirect(object sender, ImageClickEventArgs e)
    {
        //your code logic here
    
        Response.Redirect("login.aspx/?Error=2");
    }

    With Regards, 

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 12, 2018 7:33 AM