‘C#’ olarak etiketlenen yazılar

31 Oct 2008

ASP.NET CustomValidator ile optional alanlar

 
<asp:TextBox ID=”txtPhoneWork” runat=”server” Width=”300px”></asp:TextBox>

<asp:CustomValidator id=”CustomValidator1″ runat=”server” ValidateEmptyText=”true”

ControlToValidate=”txtPhoneWork” Display=”Static”

ClientValidationFunction=”ClientValidate”

ErrorMessage=”you must enter at least one of work, mobile or home phone”> *

</asp:CustomValidator>

<script language=”javascript”>

function ClientValidate(source, arguments){

if ((document.getElementById(‘<%= txtPhoneWork.ClientID %>’).value != “”)

|| (document.getElementById(‘<%= txtPhoneMobile.ClientID %>’).value != “”)

|| (document.getElementById(‘<%= txtPhoneHome.ClientID %>’).value != “”)

)

{

arguments.IsValid = true;

}else {

arguments.IsValid = false;

}

}

</script>

<asp:TextBox ID=”txtPhoneMobile” runat=”server” Width=”300px”></asp:TextBox>

<asp:TextBox ID=”txtPhoneHome” runat=”server” Width=”300px”></asp:TextBox>

<asp:ValidationSummary ID=”ValidationSummary1″ runat=”server” />