触发javascript后如何重定向到prevoius页面 [英] How to redirect to prevoius page after javascript is fired

查看:65
本文介绍了触发javascript后如何重定向到prevoius页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在单击javascript警报消息框后将页面重定向到已触发该页面的上一页.从后面的代码开始.

我的示例代码是:

How to redirect a page to the previous page from which it has been fired after clicking on javascript alert message box. from code behind.

My sample code is:

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "addmsgpay", "<script>alert('details Entered Successfully');</script>", true);

clear();
Response.Redirect("sample.aspx?");


推荐答案

如果使用updatepanel,请使用以下命令:
If you use updatepanel use this:
ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "addMsg", "<script>alert('Successfull');window.location='sample.aspx';</script>", false);


否则使用此:


otherwise use this:

ClientScript.RegisterStartupScript(GetType(), "addMsg", "<script>alert('Ticket Details Entered Successfully ');window.location='sample.aspx'</script>");


尝试一下,它对我有用

Try this, its working for me

ScriptManager.RegisterStartupScript(Page, GetType(), "Test", "alert(''details Entered Successfully'');", true);


其表现应有的状态.当您使用ScriptManager.RegisterStartupScript时,直到重新渲染Page后,您的JavaScript代码才会执行​​.而且,当您使用Response.Redirect时,它会在重新呈现当前页面并执行JavaScript代码之前重定向到其他页面.

您可以尝试使用下面的代码.
It is behaving as how it should be. When you use ScriptManager.RegisterStartupScript, your JavaScript code does not get execute untill Page gets re-rendered. And when you are using Response.Redirect, it is redirecting to other page before your current Page gets re-rendered and execute your JavaScript code.

You may try by using below code.
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "addmsgpay", "<script>alert('details Entered Successfully'); window.location.href = 'sample.aspx';</script>", true);



或者,如果您只想重定向到上一页,请使用以下代码.



Or if you simply want to redirect to the previous page then use as below code.

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "addmsgpay", "<script>alert('details Entered Successfully'); window.history.back();</script>", true);


这篇关于触发javascript后如何重定向到prevoius页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆