0

我有一个页面 A 执行Response.Redirect("~/dummyPage.aspx");. 在重定向页面(dummypage.aspx)中,我有这段代码注册了一个要在请求结束时调用的脚本。

 public void doStuff(bool isAjaxRequest)
 {
    var javascript = "alert('hello')";
    if (isAjaxRequest)
    {
        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), this.ID +  "_UpdateBreadCss", javascript, true);
    }
    else
    {
        this.Page.ClientScript.RegisterStartupScript(this.GetType(), this.ID + "_UpdateBreadCss", javascript, true);
    }
}

当我这样做时这不起作用Response.Redirect(),但如果我在 dummypage.aspx 中它工作正常。

我错过了什么?

4

2 回答 2

0

您可以通过重定向页面上的 ajax 调用来调用 doStuff 方法。在 body.onload 事件中执行 ajax 调用

于 2013-05-27T12:25:24.227 回答
0

当您使用页面后面的代码进行重定向时,不会运行并遵循重定向命令。

您可以避免对后面的代码进行重定向,运行您的脚本并使用 javascript 进行重定向。

于 2013-05-27T12:22:58.807 回答