Hello, tell me why an asynchronous request is not executed. Instead, the entire page is updated. Here is a page code snippet:

<script type="text/javascript"> function check() { var text = $get("TextBoxlogin").value; TestsApps.CheckLogin(text, onComplete) } function onComplete(result) { if (result) { $get("Labelcheck").innerHTML = "Login was used "; } else { $get("Labelcheck").innerHTML = "Login is free "; } } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager runat="server"> <Services> <asp:ServiceReference Path="~/WebService1.asmx" /> </Services> </asp:ScriptManager> Registration<table class="auto-style1"> <tr> <td> <asp:Label ID="Label1" runat="server" Text="Login"></asp:Label> </td> <td> <asp:TextBox ID="TextBoxlogin" runat="server"></asp:TextBox> <asp:Button ID="Buttoncheck" runat="server" BorderColor="#6600FF" OnClientClick="check()" Text="check" ClientIDMode="Static" /> <asp:Label ID="Labelcheck" runat="server"></asp:Label> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="TextBoxlogin" runat="server" ErrorMessage="Это поле не может быть пустым!" ForeColor="Red"></asp:RequiredFieldValidator> </td> </tr> 

Web service:

 public class WebService1 : System.Web.Services.WebService { [WebMethod(true)] public bool CheckLogin(string login) { string tmp = " "; SqlConnection connection = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename='C:\Users\Оксана\Documents\Visual Studio 2013\Projects\TestsApps\TestsApps\App_Data\Database.mdf';Integrated Security=True"); connection.Open(); using (SqlCommand cmd = connection.CreateCommand()) { cmd.CommandText = string.Format("SELECT Login FROM Profile WHERE Login = {0}", login); using (SqlDataReader r = cmd.ExecuteReader()) { while (r.Read()) { tmp+=(string)r[1]; } } } connection.Close(); if (String.Compare(tmp, login) == 0) return true; else return false; } } } 

    1 answer 1

    For this, the code in OnClientClick return false :

     <asp:Button ID="Buttoncheck" runat="server" BorderColor="#6600FF" OnClientClick="check(); return false;" Text="check" ClientIDMode="Static" /> 
    • All the same, the page is overloaded and the client code does not work - Nameless
    • @Nameless over the WebService1 class is the ScriptService attribute worth? On the page in the script, call the service through <Namespace>.WebService1.CheckLogin(text, onComplete); , instead of <Namespace> , substitute the namespace where the WebService1 class is located (although in principle the namespace should not be mandatory) - kmv
    • Thanks, helped - Nameless