在Messagebox之后重定向另一个页面 [英] Redirecting Another Page after Messagebox

查看:160
本文介绍了在Messagebox之后重定向另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



Hi All ,

messagebox("you are redirected to home page")
response.redirect("home.aspx")






此代码中的
消息框未显示。它是直接加载主页。





这里messagebox是一个具有警报脚本的函数。



如何在主题框后重定向主页?







问候,

Pal




in this code Message box is not shown. it is directly load the Home page.


here messagebox is a function which has Alert script.

How to redirect home page after the messgebox??



Regards,
Pal

推荐答案

java-script消息框通常挂在page_unload事件上。就像这里的那个:



一个Windows窗体,如MessageBox for ASP.NET Website [ ^ ]



所以如果你打电话回复.redirect调用messagebox函数后不会调用前一页的page_unload事件,并且该函数不起作用。如果你想要实现这一点,那么你应该这样做:



The java-script message boxes are typically hooked on page_unload event. Like the one here:

A Windows Form like MessageBox for ASP.NET Website[^]

so if you call response.redirect the page_unload event for the earlier page will not get called after calling the messagebox function and that wont work. IF you wanto do achieve this then you should do this:

Response.Write("<script>alert('you are redirected to home page')</script>");
Server.Transfer("home.aspx")





甚至这将起作用





or even this will work

messagebox("you are redirected to home page");
Server.Transfer("home.aspx")

<消息框出现在屏幕上时,两者都有一些细微的可见差异。



both have some minor visible difference as on when the messagebox will appear on screen.


在代码后面你可以调用javascript函数



代码背后



in code behind you can call javascript function

in code behind

string script = "Redirect();";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "Redirect", script, true);







和javascript






And in javascript

<script type="text/javascript">

function Redirect()
{
alert("Message");
    window.location="http://www.newlocation.com";
}




试试这段代码:

Hi,
Try this code :
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "InsertedMessage", "alert('you are redirected to home page');", true);
Response.Redirect("home.aspx");


这篇关于在Messagebox之后重定向另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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