加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 带有重定向的JavaScript后面的代码警报

发布时间:2020-12-15 06:41:04 所属栏目:百科 来源:网络整理
导读:之后,当我重定向到另一个页面时,如何使我的代码在代码中工作?我有一个asp按钮控件,当我点击该按钮时我想要提醒,然后导航到另一个页面.当我的代码中有一个Response.Redirect(在JS代码之前或之后)时,8次尝试都没有.当我评论重定向时,一些(2,7和8)工作. //Try
之后,当我重定向到另一个页面时,如何使我的代码在代码中工作?我有一个asp按钮控件,当我点击该按钮时我想要提醒,然后导航到另一个页面.当我的代码中有一个Response.Redirect(在JS代码之前或之后)时,8次尝试都没有.当我评论重定向时,一些(2,7和8)工作.
//Try one
ScriptManager.RegisterStartupScript(this,GetType(),"test","alert('test1');",true);

//Try two
ClientScript.RegisterClientScriptBlock(typeof(Page),"test2");

//Try three
Page.ClientScript.RegisterStartupScript(this.GetType(),"CallMyFunction","alertMessage()",true);

//Try four
ClientScript.RegisterStartupScript(GetType(),true);

//Try five
ClientScript.RegisterStartupScript(GetType(),"javascript: alertMessage(); ",true);

//Try six
ClientScript.RegisterClientScriptBlock(GetType(),"<script>alert('test4')</script>");

//Try seven
Response.Write("<script>alert('test5');</script>");

//Try eight
string script = "alert('test6')";
ScriptManager.RegisterStartupScript(Page,Page.GetType(),"CallMyString",script,true);

response.redirect("pageUrlHere");
//With this code above,none of the js functions (alerts) work

//response.redirect("pageUrlHere");
//With this commented out,try 2,7 and 8 work.

JS功能:

function alertMessage() {
    alert('test3');
}

解决方法

您可以尝试以下方法:
ScriptManager.RegisterStartupScript(this,this.GetType(),"redirect","alert('test 9'); window.location='" + 
Request.ApplicationPath + "/anotherpage.aspx';",true);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读