Дана страница:
Site.Master
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="TestWeb.SiteMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/jquery-1.4.1.js"></script>
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<asp:ContentPlaceHolder ID="ScriptPlaceHolder" runat="server">
</asp:ContentPlaceHolder>
<form runat="server">
<div class="page">
<div class="header">
<div class="title">
<h1>
My ASP.NET Application
</h1>
</div>
</div>
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</div>
<div class="clear">
</div>
</div>
<div class="footer">
</div>
</form>
</body>
</html>
Default.aspx:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="TestWeb._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>Test form</h2>
<form action="Default.aspx">
<table>
<tr>
<td><label for="name">Your name:</label></td>
<td><input type="text" id="name" /></td>
</tr>
<tr>
<td><label for="color">Your favourite color:</label></td>
<td>
<select id="color">
<option>Green</option>
<option>Red</option>
<option>Yellow</option>
</select>
</td>
</tr>
<tr>
<td><label for="18-years">You are older than 18 years</label></td>
<td><input type="checkbox" id="18-years" /></td>
</tr>
<tr>
<td>Your favourite time of day:</td>
<td>
<input type="radio" id="radio-morning" /><label for="radio-morning">Morning</label><br />
<input type="radio" id="radio-evening" /><label for="radio-evening">Evening</label><br />
<input type="radio" id="radio-night" /><label for="radio-night">Night</label><br />
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" /></td>
</tr>
</table>
</form>
</asp:Content>
Как с помощью jQuery сделать валидацию формы через AJAX на стороне сервера?
Я понимаю нужно добавить что-то вроде скрипта на страницу:
<asp:Content ID="ScriptContent" runat="server" ContentPlaceHolderID="ScriptPlaceHolder">
<script type="text/javascript">
$(document).ready(function () {
var succeededAjaxFn = function (result) {
alert("Good");
}
var failedAjaxFn = function (result) {
alert("Bad");
}
$("submit").click(function () {
var str = $( "form" ).serialize();
PageMethod("GetMeAGUID", str, succeededAjaxFn, failedAjaxFn);
});
});
</script>
</asp:Content>
А в серверный код добавить функцию валидации.
Подскажите или скажите где почитать как это сделать?