How to redirect to another page after a delay

前端 未结 3 1567
太阳男子
太阳男子 2021-02-15 12:43

I have a sign-in box in my webpage which is inside an UpdatePanel



        
相关标签:
3条回答
  • 2021-02-15 13:15

    You can write a block of Javascript with a delay and redirect to the page with this code

    public void btnSignIn_Click(object sender, EventArgs e)
    {
        lblSSuccess.Text = "We found you, now redirecting...";
        lblSSuccess.ForeColor = ColorTranslator.FromHtml("#037203");
        Session["UseIsAuthenticated"] = "true";
    
        ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "redirectJS",
        "setTimeout(function() { window.location.replace('homepage.aspx') }, 5000);", true);
    }
    
    0 讨论(0)
  • 2021-02-15 13:24

    first create a function that makes the action you need (redirect to page for example)

    Second add timer to your markup and set the time interval to 5000 ( 5 sec) and mark the timer as enabled=false so the timer wont start after the page loading

    once the user is validated successfully, show the message you want then enable the timer

    0 讨论(0)
  • 2021-02-15 13:35

    There are many ways to do this but I love to use this code because it works well when used in many different circumstances. This is with a 5 second delay.

    HtmlMeta oScript = new HtmlMeta();
    oScript.Attributes.Add("http-equiv", "REFRESH");
    oScript.Attributes.Add("content", "5; url='http://www.myurl.com/'");
    Page.Header.Controls.Add(oScript);
    
    0 讨论(0)
提交回复
热议问题