在 javascript 中使用 C# Response.Redirect 重定向到另一个页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4345960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 11:07:34  来源:igfitidea点击:

Redirecting to another page using C# Response.Redirect in javascript

c#javascript

提问by kbvishnu

I hava an aspx page and I need to response.redirect to the same page. I am doing while clicking on a button. Can i possible to do it in javascript.

我有一个 aspx 页面,我需要 response.redirect 到同一页面。我在点击按钮时正在做。我可以在 javascript 中做到这一点吗?

I tried window.location=url;. I want to know how <% Response.Redirect(url) %>can be called in javascript?

我试过了window.location=url;。我想知道如何<% Response.Redirect(url) %>在javascript中调用?

回答by Darin Dimitrov

To redirect in javascript you need to use the window.locationproperty:

要在 javascript 中重定向,您需要使用该window.location属性:

window.location = '<%= ResolveUrl("~/test.aspx") %>';

回答by andynormancx

Response.Redirectcannot be called in Javascript, that is a server side bit of code. window.locationdoes effectively the same job.

Response.Redirect不能在 Javascript 中调用,这是服务器端的代码。window.location有效地完成相同的工作。

回答by tpow

In your HTML, where you declare your button, add this.

在您声明按钮的 HTML 中,添加此项。

<input type="button" name="submit" value="submit" onclick="window.location(YOUR REDIRECT URL)" />