简体   繁体   English

asp.net中的确认消息框和页面重定向

[英]confirmation message box in asp.net and re directions of pages

I have the following javascript code in my .aspx file 我的.aspx文件中包含以下javascript代码

<script type="text/javascript">

    function checkValidation() {

        if (confirm("Data is not saved") == true) {
            window.location.href = "http://www.google.com";             
            }
        else {
            window.history.back(-1);               
            }
    }
</script>

when a button presses then the above method is called and everything work properly for external links!!! 当按下按钮时,将调用上述方法,并且外部链接一切正常!!! However when I change the statement to 但是,当我将语句更改为

window.location.href = "~/Company.aspx"; 

or 要么

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

the link is not working. 链接无效。 The links are not working if I try to navigate in my project. 如果我尝试在项目中导航,则这些链接不起作用。 I tried several statements to redirect to another page in my folders using javascript. 我尝试了一些语句,使用javascript重定向到文件夹中的另一个页面。 It is notable to say that sometimes the .aspx files are not located at the same level. 值得注意的是,有时.aspx文件不在同一级别。 For example I want to navigate for a child to a parent level. 例如,我想将孩子导航到父级。

Try this instead : 试试这个代替:

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

Or this 或这个

window.location.href = '<%= ResolveClientUrl("~/Company.aspx") >'; 

Hope this will help !! 希望这会有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM