Первым делом будет иметь скрипт на стороне сервера, который принимает параметры userid
и password
и проверяет их действительность.
Добавьте универсальный обработчик Check.ashx в ваш проект:
<%@ WebHandler Language="C#" Class="Check" %>
using System.Web;
public class Check : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
var userid = context.Request["userid"];
var password = context.Request["password"];
string response = IsValid(userid, password) ? "true" : "false";
context.Response.ContentType = "appliaction/json";
context.Response.Write("{isvalid:'" + response + "'}");
}
private bool IsValid(string userid, string password)
{
return (userid == "john" && password == "secret");
}
public bool IsReusable
{
get { return false; }
}
}
И тогда ваша страница отправит запрос ajax.
Default.aspx:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$('a.check').click(function() {
$.ajax({
url: '/check.ashx',
dataType: 'json',
data: {
userid: $('input[name=userid]').val(),
password: $('input[name=password]').val()
},
success: function(json) {
alert(json.isvalid);
}
});
return false;
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
userid: <input type="text" name="userid" value="" />
password: <input type="text" name="password" value="" />
<a href="#" class="check">Check</a>
</div>
</form>
</body>
</html>