Ho provato ma non funziona, ecco il codice:
default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<script language="javascript">
function testCognome(arg1, arg2)
{
//var RegExp = /^[a-zA-Z0-9 èéòàù']{2,25}$/;
//arg2.IsValid = RegExp.test(arg2.Value);
var valore = arg2.Value;
if(valore.length > 0)
args2.IsValid = true;
else
args2.IsValid = false;
}
function testAlfanumerico(arg1, arg2) {
var re = /^[a-zA-Z0-9]{5,}$/;
arg2.IsValid = re.test(arg2.Value);
}
</script>
<table border="0" cellpadding="0" cellspacing="0" width="500">
<tr>
<td colspan="2"><asp:Label ID="Label1" runat="server" Text="wuc1"></asp:Label></td>
</tr>
<tr>
<td>textbox1</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CustomValidator ID="cv" runat="server" ClientValidationFunction="testCognome" ControlToValidate="TextBox1" EnableClientScript="true"
ErrorMessage="errore" ValidateEmptyText="True" SetFocusOnError="true" OnServerValidate="cv_ServerValidate"></asp:CustomValidator>
</td>
</tr>
<tr>
<td>textbox2</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv1" runat="server" ErrorMessage="errore" ControlToValidate="TextBox2" EnableClientScript="true"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td colspan="2"><asp:Button ID="btn1" runat="server" Text="clicca" OnClick="btn1_Click" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void cv_ServerValidate(object source, ServerValidateEventArgs args)
{
if (args.Value.Trim().Length == 0)
args.IsValid = false;
else
args.IsValid = true;
}
protected void btn1_Click(object sender, EventArgs e)
{
if (this.Page.IsValid)
Server.Transfer("www.libero.it", false);
}
}