延迟后如何重定向到另一个页面 [英] How to redirect to another page after a delay
本文介绍了延迟后如何重定向到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的网页上有一个登录框,该登录框位于 UpdatePanel
I have a sign-in box in my webpage which is inside an UpdatePanel
<asp:UpdatePanel runat="server" ClientIDMode="Static" ID="upSign" UpdateMode="Conditional">
<ContentTemplate>
<div class="dvHolder hidOverflow clearfix">
<input id="txtSUser" type="text" name="SUsername" value="" placeholder="Username" runat="server" />
</div>
<div class="dvHolder hidOverflow clearfix">
<input id="txtSPass" type="password" name="SPassword" value="" placeholder="Password" runat="server" />
</div>
<div class="dvHolder hidOverflow clearfix setTextRight">
<asp:Button ID="btnSignIn" ClientIDMode="Static" runat="server" Text="Sign In" OnClick="btnSignIn_Click" />
<asp:Label runat="server" Text="" ID="lblSSuccess" ClientIDMode="Static" CssClass="lblMsgSuccess" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
用户成功通过验证后,我想显示一条消息,并在延迟(例如5秒钟)后重定向.我有以下代码,但未重定向:
Once the user is validated successfully, I want to show a message and redirect after a delay (let's say 5 seconds). I have the following code but it is not redirecting:
public void btnSignIn_Click(object sender, EventArgs e)
{
lblSSuccess.Text = "We found you, now redirecting...";
lblSSuccess.ForeColor = ColorTranslator.FromHtml("#037203");
Session["UseIsAuthenticated"] = "true";
Response.AppendHeader("Refresh", "5;url=homepage.aspx");
}
消息已更新,但由于某种原因页面未重定向.
The message is updated but the page is not redirecting for some reason.
请帮助我解决问题.
推荐答案
您可以延迟编写一个 Javascript
块,并使用此代码重定向到页面
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);
}
这篇关于延迟后如何重定向到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文