Hi,
I am on page 304, and do not get the desired behavior, when i request contact.aspx in browser. I have changed properties of ValidationSummery control like this.
ShowMessageBox to True and ShowSummery to False. Also i set the HeaderText property to:Please correct the following errors before you press the Send button.
When i leave out phone number textboxes in browser, and then press the send button i should be getting messagebox with list of errors preceded with the HeaderText of the validationSummery.
But, i don't get any Alert box.
here is the server side code
Code:
public partial class Controls_ContactForm : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (txtPhoneHome.Text != string.Empty || txtPhoneBusiness.Text != string.Empty)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
}
and here is the client side code
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContactForm.ascx.cs" Inherits="Controls_ContactForm" %>
<script runat="server">
</script>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
font-size: large;
font-weight: bold;
}
</style>
<script type="text/javascript">
function ValidatePhoneNumbers(source, args)
{
var txtPhoneHome = document.getElementById('<%= txtPhoneHome.ClientID %>');
var txtPhoneBusiness = document.getElementById('<%=txtPhoneBusiness.ClientID %>');
if (txtPhoneHome.value != ' ' || txtPhoneBusiness.value != ' ')
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
</script>
<table class="style1">
<tr>
<td colspan="3">
<span class="style2">Get in touch with us</span><br />
<br />
Use the form below to get in touch with us. Enter your name, e-mail address and
your home or phone number to get in touch with us.</td>
</tr>
<tr>
<td>
Your name:</td>
<td>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Please enter your name" ControlToValidate="txtName">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Your e-mail address:</td>
<td>
<asp:TextBox ID="txtEmailAddress" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtEmailAddress" Display="Dynamic"
ErrorMessage="Please enter an e-mail address">*</asp:RequiredFieldValidator>
<br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtEmailAddress" Display="Dynamic"
ErrorMessage="Please enter a valid e-mail address"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
Your e-mail address again:</td>
<td>
<asp:TextBox ID="txtEmailaddressConfirm" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtEmailaddressConfirm" Display="Dynamic"
ErrorMessage="Please confirm the email address">*</asp:RequiredFieldValidator>
<br />
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="txtEmailAddress" ControlToValidate="txtEmailaddressConfirm"
Display="Dynamic" ErrorMessage="Please retype the e-mail address">*</asp:CompareValidator>
</td>
</tr>
<tr>
<td>
Home phone number:</td>
<td>
<asp:TextBox ID="txtPhoneHome" runat="server"></asp:TextBox>
</td>
<td>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ClientValidationFunction="ValidatePhoneNumbers" Display="Dynamic"
ErrorMessage="Please enter your home or business phone number"
onservervalidate="CustomValidator1_ServerValidate">*</asp:CustomValidator>
</td>
</tr>
<tr>
<td>
Business phone number:</td>
<td>
<asp:TextBox ID="txtPhoneBusiness" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
Comments:</td>
<td>
<asp:TextBox ID="txtComments" runat="server" Height="89px"
style="margin-bottom: 0px" TextMode="MultiLine" Width="470px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="txtComments" Display="Dynamic"
ErrorMessage="Please enter comment">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnSend" runat="server" Text="Send" />
</td>
<td>
</td>
</tr>
<tr>
<td colspan="3">
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
HeaderText="Please correct the following errors before you press the send button"
ShowMessageBox="True" ShowSummary="False" />
</td>
</tr>
</table>
I am sure, somewhere i am making mistake,
thanx in advance for any help
Arya