-Dman100-
asked on
dropdown list validation problem
I have a required field validator on a dropdownlist control (EnrollmentSize) on my form that is returning false for the IsValid property even though a selection is made. It should be evaluating to true. I cannot spot what is causing the IsValid property to evaluate to talse.
Please see below for the code on the form and the code-behind.
Thanks for any help.
Please see below for the code on the form and the code-behind.
Thanks for any help.
aspx page:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SupportForm.ascx.cs" Inherits="Controls_SupportForm" %>
<p><asp:Literal ID="formHeader" runat="server" Text="Please let us know how we can help you:"></asp:Literal></p>
<div id="contactForm" runat="server" class="contact-form">
<asp:RadioButtonList
ID="SupportType"
RepeatLayout="flow"
RepeatColumns="1"
RepeatDirection="Horizontal"
ToolTip="Choose your support need"
OnSelectedIndexChanged="SupportType_SelectedIndexChanged"
runat="server"
AutoPostBack="true">
<asp:ListItem Text="I want to provide feedback, an idea or comment." Value="support" />
<asp:ListItem Text="I would like to request more information." Value="products" />
</asp:RadioButtonList>
<asp:Panel ID="Panel1" runat="server" Visible="False">
<fieldset>
<legend>
<asp:Literal ID="SupportTypeTitle" runat="server" Mode="PassThrough" Text="Request Technical Support Assistance" />
</legend>
<p><span class="required"><strong>NOTE:</strong> All fields are required.</span></p>
<input name="elqCustomerGUID" type="hidden" />
<!-- First Name ............................................................... -->
<asp:RequiredFieldValidator
ID="ValidatorFirstName"
runat="server"
ControlToValidate="firstname"
EnableClientScript="False"
SetFocusOnError="true"
ErrorMessage="<span class='alert'>First Name:</span>"
Display="dynamic"
Enabled="False"></asp:RequiredFieldValidator>
<span><label for="firstname" id="lblFirstName" runat="server">First Name:</label></span>
<asp:TextBox
ID="firstname"
runat="server"
CausesValidation="true"
TextMode="SingleLine"
ToolTip="First Name"></asp:TextBox>
<!-- Last Name ................................................................ -->
<asp:RequiredFieldValidator
ID="ValidatorLastName"
runat="server"
ControlToValidate="lastname"
EnableClientScript="False"
SetFocusOnError="true"
ErrorMessage="<span class='alert'>Last Name:</span>"
Display="dynamic"
Enabled="False"></asp:RequiredFieldValidator>
<span><label for="lastname" id="lblLastName" runat="server">Last Name:</label></span>
<asp:TextBox
ID="lastname"
runat="server"
CausesValidation="true"
TextMode="SingleLine"
ToolTip="Last Name"></asp:TextBox>
<!-- Email .................................................................... -->
<asp:RequiredFieldValidator
ID="ValidatorEmail"
runat="server"
ControlToValidate="email"
EnableClientScript="False"
SetFocusOnError="true"
ErrorMessage="<span class='alert'>E-mail:</span>"
Display="dynamic"
Enabled="False"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="valeEmail"
runat="server"
ControlToValidate="email"
SetFocusOnError="true"
ErrorMessage="<span class='alert'>E-mail:</span>"
Display="dynamic"
Enabled="false"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
<span><label for="email" id="lblEmail" runat="server">E-mail:</label></span>
<asp:TextBox
ID="email"
runat="server"
CausesValidation="true"
TextMode="SingleLine"
ToolTip="Email Address"></asp:TextBox>
<!-- Organization ............................................................. -->
<asp:RequiredFieldValidator
ID="ValidatorOrganization"
runat="server"
Enabled="False"
ControlToValidate="organization"
EnableClientScript="False"
SetFocusOnError="true"
ErrorMessage="<span class='alert'>Organization:</span>"
Display="dynamic"></asp:RequiredFieldValidator>
<span><label for="organization" id="lblOrganization" runat="server">Organization:</label></span>
<asp:TextBox
ID="organization"
runat="server"
CausesValidation="true"
TextMode="SingleLine"
ToolTip="Organization"></asp:TextBox>
<!-- Level ................................................................... -->
<asp:RequiredFieldValidator
ID="ValidatorLevel"
runat="server"
ControlToValidate="level"
EnableClientScript="False"
SetFocusonError="true"
ErrorMessage="<span class='alert'>Level:</span>"
Display="dynamic"
Enabled="false"></asp:RequiredFieldValidator>
<span><label for="level" id="lblLevel" runat="server">Level:</label></span>
<asp:DropDownList ID="level" runat="server" OnSelectedIndexChanged="level_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Selected="True">Please select...</asp:ListItem>
<asp:ListItem Value="District">District</asp:ListItem>
<asp:ListItem Value="School">School</asp:ListItem>
<asp:ListItem Value="State">State</asp:ListItem>
<asp:ListItem Value="Other">Other</asp:ListItem>
</asp:DropDownList>
<!-- Job Role ................................................................ -->
<asp:RequiredFieldValidator
ID="ValidatorJobRole"
runat="server"
ControlToValidate="JobRole"
EnableClientScript="False"
SetFocusonError="true"
ErrorMessage="<span class='alert'>Job Role:</span>"
Display="dynamic"
Enabled="false"></asp:RequiredFieldValidator>
<span><label for="jobrole" id="lblJobRole" runat="server">Job Role:</label></span>
<asp:DropDownList ID="JobRole" runat="server">
<asp:ListItem Selected="True" Value="">Please select...</asp:ListItem>
<asp:ListItem Value="Superintendent">Superintendent</asp:ListItem>
<asp:ListItem Value="Asst. Superintendent">Asst. Superintendent</asp:ListItem>
<asp:ListItem Value="Executive Officer">Executive Officer</asp:ListItem>
<asp:ListItem Value="Director">Director</asp:ListItem>
<asp:ListItem Value="Coordinator">Coordinator</asp:ListItem>
<asp:ListItem Value="Specialist">Specialist</asp:ListItem>
<asp:ListItem Value="Administration">Administration</asp:ListItem>
<asp:ListItem Value="School Board Member">School Board Member</asp:ListItem>
<asp:ListItem Value="Other">Other</asp:ListItem>
<asp:ListItem Value="Principal">Principal</asp:ListItem>
<asp:ListItem Value="Asst. Pricipal">Asst. Principal</asp:ListItem>
<asp:ListItem Value="Headmaster">Headmaster</asp:ListItem>
<asp:ListItem Value="Teacher">Teacher</asp:ListItem>
<asp:ListItem Value="Student">Student</asp:ListItem>
<asp:ListItem Value="Parent">Parent</asp:ListItem>
<asp:ListItem Value="Secretary">Secretary</asp:ListItem>
<asp:ListItem Value="CEO">CEO</asp:ListItem>
<asp:ListItem Value="CTO">CTO</asp:ListItem>
<asp:ListItem Value="Other Executive Officer">Other Executive Officer</asp:ListItem>
<asp:ListItem Value="Commissioner">Commissioner</asp:ListItem>
<asp:ListItem Value="Legislator">Legislator</asp:ListItem>
<asp:ListItem Value="Coach">Coach</asp:ListItem>
<asp:ListItem Value="Administrative Assistant">Administrative Assistant</asp:ListItem>
<asp:ListItem Value="Home School">Home School</asp:ListItem>
<asp:ListItem Value="Role (School)">Role (School)</asp:ListItem>
</asp:DropDownList>
<!-- Area of Responsibility ..................................................... -->
<asp:RequiredFieldValidator
ID="ValidatorAreaOfResponsibility"
runat="server"
ControlToValidate="AreaOfResponsibility"
EnableClientScript="False"
SetFocusonError="true"
ErrorMessage="<span class='alert'>Area of Responsibility:</span>"
Display="dynamic"
Enabled="false"></asp:RequiredFieldValidator>
<span><label for="areaofresponsibility" id="lblAreaOfResponsibility" runat="server">Area of Responsibility:</label></span>
<asp:DropDownList ID="AreaOfResponsibility" runat="server">
<asp:ListItem Selected="True" Value="">Please select...</asp:ListItem>
<asp:ListItem Value="Executive Administration">Executive Administration</asp:ListItem>
<asp:ListItem Value="Special Needs">Special Needs</asp:ListItem>
<asp:ListItem Value="Curriculum">Curriculum</asp:ListItem>
<asp:ListItem Value="Technology">Technology</asp:ListItem>
<asp:ListItem Value="Federal Programs">Federal Programs</asp:ListItem>
<asp:ListItem Value="Instruction">Instruction</asp:ListItem>
<asp:ListItem Value="Office Administration">Office Administration</asp:ListItem>
<asp:ListItem Value="Other">Other</asp:ListItem>
</asp:DropDownList>
<!-- Enrollment Size ......................................................... -->
<asp:RequiredFieldValidator
ID="ValidatorEnrollmentSize"
runat="server"
ControlToValidate="EnrollmentSize"
EnableClientScript="False"
SetFocusonError="true"
ErrorMessage="<span class='alert'>Enrollment Size:</span>"
Display="dynamic"
Enabled="false"></asp:RequiredFieldValidator>
<span><label for="enrollmentsize" id="lblEnrollmentSize" runat="server">Enrollment Size:</label></span>
<asp:DropDownList ID="EnrollmentSize" runat="server">
<asp:ListItem Value="">Please Select...</asp:ListItem>
</asp:DropDownList>
<!-- Grade Level ............................................................. -->
<asp:CustomValidator
ID="valxGradeLevel"
runat="server"
EnableClientScript="false"
SetFocusOnError="true"
ErrorMessage="<span class='alert'>Grade Level:</span>"
Display="dynamic"
OnServerValidate="valxGradeLevel_ServerValidate"
Enabled="False"></asp:CustomValidator>
<span><label for="gradelevel" id="lblGradeLevel" runat="server">Grade Level:</label></span>
<asp:CheckBoxList runat="server" ID="GradeLevel" TextAlign="right" RepeatLayout="flow" RepeatDirection="Horizontal" CssClass="checkbox-list">
<asp:ListItem Value="Elementary">Elementary</asp:ListItem>
<asp:ListItem Value="Middle">Middle</asp:ListItem>
<asp:ListItem Value="High">High</asp:ListItem>
<asp:ListItem Value="Vocational">Vocational</asp:ListItem>
<asp:ListItem Value="Alternative">Alternative</asp:ListItem>
<asp:ListItem Value="Higher Ed">Higher Ed</asp:ListItem>
</asp:CheckBoxList>
<div style="clear:both;"></div>
<!-- Country .................................................................. -->
<asp:RequiredFieldValidator
ID="ValidatorCountry"
runat="server"
ControlToValidate="Country"
EnableClientScript="False"
SetFocusonError="true"
ErrorMessage="<span class='alert'>Country:</span>"
Display="dynamic"
Enabled="false"></asp:RequiredFieldValidator>
<span><label for="country" id="lblCountry" runat="server">Country:</label></span>
<asp:DropDownList
ID="Country"
runat="server"
AppendDataBoundItems="true"
DataSourceID="CountriesDataSource"
DataTextField="Name"
DataValueField="Name">
<asp:ListItem Selected="True" Value="">Please select...</asp:ListItem>
</asp:DropDownList>
<!-- State .................................................................... -->
<asp:RequiredFieldValidator
ID="ValidatorState"
runat="server"
ControlToValidate="state"
EnableClientScript="False"
SetFocusonError="true"
ErrorMessage="<span class='alert'>State:</span>"
Display="dynamic"
Enabled="false"></asp:RequiredFieldValidator>
<span><label for="state" id="lblState" runat="server">State:</label></span>
<asp:DropDownList
ID="state"
runat="server"
AppendDataBoundItems="true"
DataSourceID="StatesDataSource"
DataTextField="Name"
DataValueField="StateAbr">
<asp:ListItem Selected="True" Value="">Please select...</asp:ListItem>
</asp:DropDownList>
<!-- Zip ...................................................................... -->
<asp:RequiredFieldValidator
ID="ValidatorZipcode"
runat="server"
ControlToValidate="zip"
EnableClientScript="False"
SetFocusOnError="true"
ErrorMessage="<span class='alert'>Zip:</span>"
Display="dynamic"
Enabled="False"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="valeZip"
runat="server"
ControlToValidate="zip"
Display="Dynamic"
EnableClientScript="False"
Enabled="False"
ErrorMessage="<span class='alert'>Zip:</span>"
ValidationExpression="\d{5}(-\d{4})?"></asp:RegularExpressionValidator>
<span><label for="zip" id="lblZip" runat="server">Zip:</label></span>
<asp:TextBox
ID="zip"
CssClass="zip"
runat="server"
MaxLength="5"
CausesValidation="true"
TextMode="SingleLine"
ToolTip="Zip/Postal Code"></asp:TextBox>
<!-- Phone .................................................................... -->
<asp:CustomValidator
ID="valxContactPhoneNumber"
runat="server"
EnableClientScript="false"
SetFocusOnError="true"
ErrorMessage="<span class='alert'>Phone Number:</span>"
Display="dynamic"
OnServerValidate="valxContactPhoneNumber_ServerValidate"
Enabled="False"></asp:CustomValidator>
<span><label for="phone" id="lblPhone" runat="server">Phone:</label></span>
<div class="phonebox">
<asp:TextBox
ID="phoneAreaCode"
CssClass="phone"
runat="server"
CausesValidation="true"
TextMode="SingleLine"
MaxLength="3"
ToolTip="Phone Number Area Code"></asp:TextBox>
<asp:TextBox
ID="phonePrefix"
CssClass="phone"
runat="server"
MaxLength="3"
CausesValidation="true"
TextMode="SingleLine"
ToolTip="Phone Number Prefix"></asp:TextBox>
<asp:TextBox
ID="phoneSuffix"
CssClass="phone"
runat="server"
MaxLength="4"
CausesValidation="true"
TextMode="SingleLine"
ToolTip="Phone Number Suffix"></asp:TextBox>
</div>
<!-- Areas of Interest ........................................................ -->
<span><label for="areasofinterest" id="lblAreasOfInterest" runat="server">Areas of Interest:</label></span>
<asp:ListBox
ID="AreasOfInterest"
runat="server"
SelectionMode="Multiple"
ToolTip="Areas of Interest">
<asp:ListItem Value="Credit Recovery">Credit Recovery</asp:ListItem>
<asp:ListItem Value="Alternate Education">Alternate Education</asp:ListItem>
<asp:ListItem Value="Response to Intervention">Response to Intervention</asp:ListItem>
<asp:ListItem Value="Algebra Readiness">Algebra Readiness</asp:ListItem>
<asp:ListItem Value="Special Needs">Special Needs</asp:ListItem>
<asp:ListItem Value="Title 1">Title 1</asp:ListItem>
<asp:ListItem Value="K-8">K–8</asp:ListItem>
<asp:ListItem Value="High School">High School</asp:ListItem>
<asp:ListItem Value="College Readiness">College Readiness</asp:ListItem>
<asp:ListItem Value="Results/Reporting">Results/Reporting</asp:ListItem>
<asp:ListItem Value="NWEA">NWEA</asp:ListItem>
<asp:ListItem Value="ELL/ESL">ELL/ESL</asp:ListItem>
</asp:ListBox>
<!-- Description of Problem ................................................... -->
<asp:CustomValidator
ID="ValidatorQuestion"
runat="server"
EnableClientScript="false"
SetFocusOnError="true"
Display="dynamic"
OnServerValidate="ValidatorQuestion_ServerValidate"
Enabled="False" ForeColor=""></asp:CustomValidator>
<asp:Literal ID="lblComment" runat="server"></asp:Literal>
<asp:TextBox
ID="comment"
runat="server"
CausesValidation="true"
TextMode="multiLine"
Columns="20"
Rows="4"
Wrap="true"
ToolTip="Description of Problem"></asp:TextBox>
<!-- Submit Button ............................................................ -->
<asp:ImageButton
ID="SubmitButton"
CssClass="submit"
ImageUrl="~/images/button-contact-submit.gif"
runat="server"
OnClick="SubmitButton_Click"
ToolTip="Press to submit" />
<asp:ImageButton
ID="ResetButton"
CssClass="submit"
ImageUrl="~/images/button-contact-reset.gif"
runat="server"
EnableViewState="False"
OnClick="ResetButton_Click"
ToolTip="Press to reset" CausesValidation="False" />
</fieldset>
</asp:Panel>
</div>
<asp:ObjectDataSource
ID="ProdTypesDataSource"
runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetProductTypes"
TypeName="CompassLearning.Data.DataManager"></asp:ObjectDataSource>
<asp:ObjectDataSource
ID="ImplTypesDataSource"
runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetImplementationTypes"
TypeName="CompassLearning.Data.DataManager"></asp:ObjectDataSource>
<asp:ObjectDataSource
ID="StatesDataSource"
runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetStates"
TypeName="CompassLearning.Data.DataManager"></asp:ObjectDataSource>
<asp:ObjectDataSource
ID="CountriesDataSource"
runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetCountries"
TypeName="PopulateCountriesList"></asp:ObjectDataSource>
code-behind:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
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;
using System.Text.RegularExpressions;
using CompassLearning.Data.Models;
using CompassLearning.Data;
using System.Text;
using postme;
public partial class Controls_SupportForm : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
sb.Append("<script type=\"text/javascript\" language=\"Javascript\">\n");
sb.Append("var jlcProt = ((location.protocol==\"https:\") ? \"https:\" : \"http:\");\n");
sb.Append("document.write('<script type=\"text/javascript\" language=\"Javascript\" src=\"' + jlcProt + ");
sb.Append("'//sftrack.searchforce.net/SFConversionTracking/CTCommon.js\"><\\/script>');");
sb.Append("</script>\n");
sb.Append("<script type=\"text/javascript\" language=\"Javascript\">\n");
sb.Append("var jValue = \"\";\n");
sb.Append("var jOrderID = \"\";\n");
sb.Append("var jconversion_type = \"lead\";\n");
sb.Append("var jvar1=\"\";\n");
sb.Append("var jvar2=\"\";\n");
sb.Append("var jvar3=\"\";\n");
sb.Append("var jprotocol = \"http\"; if(location.protocol == \"https:\"){jprotocol = \"https\";} ImageJSConversionProcess();\n");
sb.Append("</script>\n");
if (IsProductRequest)
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "conversioncode", sb.ToString(), false);
}
}
protected void SubmitButton_Click(object sender, ImageClickEventArgs e)
{
EnableValidators(true);
Page.Validate();
if (Page.IsValid)
{
if (SupportType.SelectedIndex == 0)
{
RemotePost rp = new RemotePost();
rp.Url = "http://now.eloqua.com/e/f2.aspx";
rp.Add("elqFormName", "ContactUs_Form");
rp.Add("elqSiteID", "1551");
rp.Add("elqCustomerGUID", Request.Form["elqCustomerGUID"]);
rp.Add("elqCookieWrite", "0");
rp.Add("txtFirstName", firstname.Text.ToString());
rp.Add("txtLastName", lastname.Text.ToString());
rp.Add("txtEmailAddress", email.Text.ToString());
rp.Add("txtOrganization", organization.Text.ToString());
rp.Add("txtLevel", level.SelectedValue.ToString());
rp.Add("txtFeedback", comment.Text.ToString());
rp.Post();
}
else
{
RemotePost rp = new RemotePost();
rp.Url = "http://now.eloqua.com/e/f2.aspx";
rp.Add("elqFormName", "ContactUs_Form");
rp.Add("elqSiteID", "1551");
rp.Add("elqCustomerGUID", Request.Form["elqCustomerGUID"]);
rp.Add("elqCookieWrite", "0");
rp.Add("txtFirstName", firstname.Text.ToString());
rp.Add("txtLastName", lastname.Text.ToString());
rp.Add("txtEmailAddress", email.Text.ToString());
rp.Add("txtOrganization", organization.Text.ToString());
rp.Add("txtLevel", level.SelectedValue.ToString());
rp.Add("txtJobRole", JobRole.SelectedValue.ToString());
rp.Add("txtResponsibilty", AreaOfResponsibility.SelectedValue.ToString());
if (level.SelectedValue.ToString().ToLower() == "district")
{
rp.Add("txtEnrollmentSizeDistrict", EnrollmentSize.SelectedValue.ToString());
}
if (level.SelectedValue.ToString().ToLower() == "school")
{
rp.Add("txtEnrollmentSizeSchool", EnrollmentSize.SelectedValue.ToString());
}
string gradeLevel = null;
for (int i = 0; i < GradeLevel.Items.Count - 1; i++)
{
gradeLevel = GradeLevel.Items[i].Text + ", ";
}
rp.Add("txtGradeLevel", gradeLevel);
rp.Add("txtCountry", Country.SelectedValue.ToString());
rp.Add("txtState", state.SelectedValue.ToString());
rp.Add("txtPostalCode", zip.Text.ToString());
string phone = phoneAreaCode.Text.ToString() + phonePrefix.Text.ToString() + phoneSuffix.Text.ToString();
rp.Add("txtPhone", phone);
string AofI = null;
for (int i = 0; i <= AreasOfInterest.Items.Count - 1; i++)
{
AofI = AreasOfInterest.Items[i].Text + ", ";
}
rp.Add("txtAreaOfInterest", AofI);
rp.Post();
}
}
else
{
ValidateControls();
}
}
protected void EnableValidators(bool toggle)
{
ValidatorFirstName.Enabled = toggle;
ValidatorLastName.Enabled = toggle;
ValidatorEmail.Enabled = toggle;
ValidatorOrganization.Enabled = toggle;
ValidatorLevel.Enabled = toggle;
valeEmail.Enabled = toggle;
if (SupportType.SelectedIndex == 0)
{
ValidatorJobRole.Enabled = false;
ValidatorAreaOfResponsibility.Enabled = false;
ValidatorEnrollmentSize.Enabled = false;
ValidatorCountry.Enabled = false;
ValidatorState.Enabled = false;
ValidatorZipcode.Enabled = false;
valeZip.Enabled = false;
valxContactPhoneNumber.Enabled = false;
ValidatorQuestion.Enabled = true;
}
else
{
ValidatorJobRole.Enabled = true;
ValidatorAreaOfResponsibility.Enabled = true;
if (level.SelectedValue.ToString().ToLower() == "district" || level.SelectedValue.ToString().ToLower() == "school")
{
ValidatorEnrollmentSize.Enabled = true;
}
valxGradeLevel.Enabled = true;
ValidatorCountry.Enabled = true;
ValidatorState.Enabled = true;
ValidatorZipcode.Enabled = true;
valeZip.Enabled = true;
valxContactPhoneNumber.Enabled = true;
ValidatorQuestion.Enabled = false;
}
}
protected void ValidateControls()
{
HtmlGenericControl[] controls = { lblFirstName, lblLastName, lblCountry,
lblState, lblZip, lblEmail, lblOrganization, lblLevel, lblJobRole, lblAreaOfResponsibility,
lblEnrollmentSize, lblGradeLevel };
IValidator[][] validators = {
new IValidator[] { ValidatorFirstName },
new IValidator[] { ValidatorLastName },
new IValidator[] { ValidatorState }, new IValidator[] { ValidatorCountry },
new IValidator[] { ValidatorZipcode, valeZip },
new IValidator[] { ValidatorEmail, valeEmail }, new IValidator[] { ValidatorOrganization },
new IValidator[] { ValidatorLevel }, new IValidator[] { ValidatorJobRole }, new IValidator[] { ValidatorAreaOfResponsibility },
new IValidator[] { ValidatorEnrollmentSize }, new IValidator[] { valxGradeLevel } };
for (int i = 0; i < controls.Length; i++)
{
bool valid = true;
foreach (IValidator validator in validators[i])
{
valid &= validator.IsValid;
}
controls[i].Visible = valid;
}
}
protected void valxContactPhoneNumber_ServerValidate(object source, ServerValidateEventArgs args)
{
String areacodeRegex = "\\d{3}";
String prefixRegex = "\\d{3}";
String suffixRegex = "\\d{4}";
if ((!Regex.IsMatch(phoneAreaCode.Text, areacodeRegex)
|| (!Regex.IsMatch(phonePrefix.Text, prefixRegex) || (!Regex.IsMatch(phoneSuffix.Text, suffixRegex)))))
{
args.IsValid = false;
lblPhone.Attributes.CssStyle.Add("display", "none");
}
else
{
args.IsValid = true;
lblPhone.Attributes.Clear();
}
}
protected void valxGradeLevel_ServerValidate(object source, ServerValidateEventArgs args)
{
foreach (ListItem li in GradeLevel.Items)
{
if (li.Selected)
{
args.IsValid = true;
break;
}
else
{
args.IsValid = false;
}
}
}
protected void ValidatorQuestion_ServerValidate(object source, ServerValidateEventArgs args)
{
if (comment.Text.Length > 500)
{
args.IsValid = false;
ValidatorQuestion.ErrorMessage = "<span class='alert'>Maximum 500 character limit</span>";
lblComment.Visible = false;
}
else if (comment.Text.Length < 4)
{
args.IsValid = false;
ValidatorQuestion.ErrorMessage = "<span class='alert'>Minimum 4 characters required</span>";
lblComment.Visible = false;
}
else
{
args.IsValid = true;
lblComment.Visible = true;
}
}
protected void ResetButton_Click(object sender, ImageClickEventArgs e)
{
cleanFields(this);
}
protected void SupportType_SelectedIndexChanged(object sender, EventArgs e)
{
Panel1.Visible = true;
}
public bool IsSupportRequest
{
get { return SupportType.SelectedIndex == 0; }
}
public bool IsProductRequest
{
get { return SupportType.SelectedIndex == 1; }
}
protected void cleanFields(Control container)
{
foreach (Control c in container.Controls)
{
if (c is TextBox)
{
((TextBox)c).Text = string.Empty;
}
if (c is DropDownList)
{
((DropDownList)c).SelectedIndex = -1;
}
if (c is RadioButtonList)
{
((RadioButtonList)c).ClearSelection();
}
if (c is Panel)
{
((Panel)c).Visible = false;
}
this.cleanFields(c);
}
}
protected void prodtype_DataBound(object sender, EventArgs e)
{
prodtype.Items.Insert(0, new ListItem("Please select...", ""));
}
protected void ddlImplementationType_DataBound(object sender, EventArgs e)
{
ddlImplementationType.Items.Insert(0, new ListItem("Please select...", ""));
}
protected void Page_PreRender()
{
if (SupportType.SelectedIndex == 0)
{
currcust.Visible = false;
lblCurrCust.Visible = false;
ddlImplementationType.Visible = false;
lblImplementationType.Visible = false;
JobRole.Visible = false;
lblJobRole.Visible = false;
ValidatorJobRole.Visible = false;
AreaOfResponsibility.Visible = false;
lblAreaOfResponsibility.Visible = false;
ValidatorAreaOfResponsibility.Visible = false;
EnrollmentSize.Visible = false;
lblEnrollmentSize.Visible = false;
ValidatorEnrollmentSize.Visible = false;
GradeLevel.Visible = false;
lblGradeLevel.Visible = false;
valxGradeLevel.Visible = false;
Country.Visible = false;
lblCountry.Visible = false;
ValidatorCountry.Visible = false;
state.Visible = false;
lblState.Visible = false;
ValidatorState.Visible = false;
zip.Visible = false;
lblZip.Visible = false;
ValidatorZipcode.Visible = false;
valeZip.Visible = false;
phoneAreaCode.Visible = false;
phonePrefix.Visible = false;
phoneSuffix.Visible = false;
lblPhone.Visible = false;
valxContactPhoneNumber.Visible = false;
AreasOfInterest.Visible = false;
lblAreasOfInterest.Visible = false;
SupportTypeTitle.Text = "Ask Us a Question or Share Your Comments";
lblComment.Text = "<span><label>Feedback, Ideas, or Comments</label></span>";
}
else
{
lblCurrCust.Visible = false;
currcust.Visible = false;
prodtype.Visible = false;
lblProdType.Visible = false;
lblLabno.Visible = false;
labnum.Visible = false;
SupportTypeTitle.Text = "Request Information About Our Customer Solutions";
lblComment.Text = "<span><label>Comment or Question:</label></span>";
comment.Visible = false;
lblComment.Visible = false;
ValidatorQuestion.Visible = false;
}
}
protected void level_SelectedIndexChanged(object sender, EventArgs e)
{
string sv = level.SelectedValue;
switch (sv)
{
case "District":
EnrollmentSize.Items.Insert(1, ">24,000 Schools");
EnrollmentSize.Items.Insert(2, "15,001 - 24,000 Schools");
EnrollmentSize.Items.Insert(3, "2,001 - 15,000 Schools");
EnrollmentSize.Items.Insert(4, "1 - 2,000 Schools");
break;
case "School":
EnrollmentSize.Items.Insert(1, ">2,000 Students");
EnrollmentSize.Items.Insert(2, "501 - 1,999 Students");
EnrollmentSize.Items.Insert(3, "151 - 500 Students");
EnrollmentSize.Items.Insert(4, "<150 Students");
break;
default:
break;
}
}
}
ASKER
I set a breakpoint on the SubmitButton_Click event handler and stepped thru the code. The IsValid property shows false in the debug. The DDL for Enrollment Size shows empty an empty string even though in the form, I've selected the option ">2,000". It isn't picking up the value that has been selected. I don't see why or how that is happening? I'm making a selection and I've looked at the page source and it the values are correctly listed.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks for the help on this one. I was never able to figure out the issue.
Did you try setting debugging and see in code behind what is the selectedValue for that DDL?