在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");