asp.net ajax no refresh authentication username

Source: Internet
Author: User

Extremely simple, self expanding

HTML code

<%@ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>

<! DOCTYPE HTML PUBLIC "-//w3c//dtd XHTML 1.1//en" "Http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >
<title>untitled page</title>
<script type= "Text/javascript" >
function GetUser ()
{
Requestsimpleservice = Webservicesample.getuser (document.getElementById (' UserName '). value, Onrequestcomplete);
return false;
}
Show Tips
function Onrequestcomplete (Result)
{
if (result = = ' true ')
{
document.getElementById (' message '). InnerHTML = ' Hint: User name has been registered. '
document.getElementById (' Postbutton '). Disabled = ' disabled ';
}
Else
{
document.getElementById (' message '). InnerHTML = ' Hint: User name can use. '
document.getElementById (' Postbutton '). Disabled = ";
}
}
</script>
<body>
<form id= "form1″runat=" Server >
<asp:scriptmanager id= "scriptmanager1″runat=" Server >
<Services>
<asp:servicereference path= "Webservicesample.asmx"/>
</Services>
</asp:ScriptManager>
<input id= "UserName" type= "text" onblur= "return GetUser ()"/>
<input id= "Postbutton" type= "button" value= "register" disabled= "disabled"/><br/>
<div id= "Message" ></div>
</form>
</body>

WebService code

using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;

/// <summary>
/// WebServiceSample 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]

public class WebServiceSample : System.Web.Services.WebService
{

  public WebServiceSample () {

    //如果使用设计的组件,请取消注释以下行
    //InitializeComponent();
  }

  [WebMethod]
  public string GetUser(string strUser)
  {
    string strMessage = null;
    if (strUser == “ADMIN”)
    {
      strMessage = “true”;
    }
    else
    {
      strMessage = “false”;
    }
    return strMessage;
  }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.