简体   繁体   中英

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

I have the following javascript code in my .aspx file

<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. It is notable to say that sometimes the .aspx files are not located at the same level. 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 !!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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