2

i simply want the button click to redirect to a different page.. at the beginning my code looked like this :

<asp:Button runat="server" ID="Register_BTN" Text="Register here !" 
 OnClientClick="Register_BTN_Click();"/>

<script type-"text/javascript">
  function Register_BTN_Click() {
        window.location.href("Registration.aspx");
    }


the error that was thrown : Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.

i have searched about it online and found this question : JavaScript console.log causes error: "Synchronous XMLHttpRequest on the main thread is deprecated..."

later i changed the code :

<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
     $.ajaxSetup({async:true});
    function Register_BTN_Click() {
        window.location.href("Registration.aspx");
    }


and still same exception.. also tried this change and it didn't help..

<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
                 $.ajax({
           async: true,   // this will solve the problem
           type: "POST",
           url: "/Page/Method",
           contentType: "application/json",
           data: JSON.stringify({ ParameterName: paramValue }),
        });
    function Register_BTN_Click() {
        window.location.hash("Registration.aspx");
    }

how can i fix this ? Thanks

Community
  • 1
  • 1
zzzz
  • 161
  • 1
  • 9
  • 2
    If you want to create a link then just create a link, anchor (a-element) is for that purpose. Don't make things more complicated than they are. You can style the link to look like a button if needed. – Esko May 12 '17 at 12:27
  • You [can't have a `src` attribute and inline code in the same ` – George May 12 '17 at 12:32

2 Answers2

2

window.location.href is a property, not a function, and you should use it like this:

window.location.href = "Registration.aspx";
Peter B
  • 22,460
  • 5
  • 32
  • 69
  • thanks i changed it accordingly but the same exception is still thrown.. – zzzz May 12 '17 at 12:40
  • What is the purpose of your `$.ajax(...)` call? Does it even have a purpose? It looks very much like a stub at the moment. If all you want is to *show the Registration page* when the button is clicked, then just try removing all the ajax stuff. The single line of code in my answer (placed in your function) will be all you need in that case. Or if the ajax has a purpose, then please show more of your actual code. – Peter B May 12 '17 at 13:21
  • i tried running it as u said : function Register_BTN_Click() { window.location.href = "Registration.aspx"; } with no ajax..but still the exception is thrown...i added the ajax because in this link - stackoverflow.com/questions/24639335/… they said it may solve the exception but it doesnt.. – zzzz May 12 '17 at 15:29
0

it works when i change the asp control to an html control for example :

this solution doesnt work :

<asp:Button runat="server" ID="Register_BTN" Text="Register here !" 
    OnClientClick="Register_BTN_Click();"/>

<script type-"text/javascript">
  function Register_BTN_Click() {
        window.location.href="Registration.aspx";
    }

but this one does :

 <input type="button" value="Register here !" onclick="Register_BTN_Click();" id="Register_BTN" />
    <script type="text/javascript" >
       function Register_BTN_Click() {
           window.location.href = "Registration.aspx";
            
        }
   </script>       
can someone tell me why when i use the asp control i get this error thrown : - Synchronous XMLHttpRequest on the main thread is deprecated
zzzz
  • 161
  • 1
  • 9