Gail Cooper

Gail Cooper

  • NA
  • 1
  • 0

Custom Validators & Server Side Prodcedures

Mar 16 2009 10:17 AM

Hi,

I'm new to all this and am having huge difficulty with the following piece of code, what I'm aiming for in this is to validate a TextBox (editCallBack) based on the selected value of a drop down list (editStatusTextBox) - If editStatusTextBox = "Call Attempt 1" or editStatusTextBox = "Call Attempt 2" and then editCallBack must have a value, what I'm getting with the below code is the error message thrown up if I have a value in editCallBack, not if its null :(

 

<%@ Page Language="C#" %>

<script runat="server">

void Button1_Click(Object sender, EventArgs e)

{

if (Page.IsValid)

{

Label1.Text = "Page is Valid";

}

else

{

Label1.Text = "Page Not Valid";

}

}

 

 

 

 

void ValidateNumber(object source, ServerValidateEventArgs args)

{

 

try

{

 

 

 

 

 

 

 

 

 

 

 

 

 

 

if ((Eval(editCallBack.Text) == null) && this.editStatusTextBox.Text == "Call Attempt 1")

{

 

 

args.IsValid = false;

}

else if ((Eval(editCallBack.Text) == null) && this.editStatusTextBox.Text == "Call Attempt 2")

{

args.IsValid = false;

}

 

 

 

 

}

catch (Exception ex)

{

args.IsValid = false;

}

}

 

 

 

 

 

 

</script>

<html>

<head>

</head>

<body>

<form id="Form1" runat="server">

<p>

Outcome:

<asp:DropDownList ID="editStatusTextBox" runat="server"

CausesValidation="True" >

<asp:ListItem Selected="true" Value="Call Attempt 1" Text="Call Attempt 1"/>

<asp:ListItem Value="Call Attempt 2" Text="Call Attempt 2"/>

<asp:ListItem Value="Contacted - Interested" Text="Contacted - Interested"/>

<asp:ListItem Value="Contacted - Not Interested" Text="Contacted - Not interested"/>

<asp:ListItem Value="Callback Required" Text="Callback Required"/>

<asp:ListItem Value="Not in Business" Text="Not in Business"/>

<asp:ListItem Value="Number not in use" Text="Number not in use"/>

<asp:ListItem Value="Using alternative product" Text="Using alternative product"/>

<asp:ListItem Value="Nurture" Text="Nurture"/>

</asp:DropDownList>

Date:

<asp:TextBox id="editCallBack"

runat="server"></asp:TextBox>

&nbsp;

<asp:CustomValidator id="CustomValidator1"

runat="server" ControlToValidate="editCallBack"

ErrorMessage="You must enter a Date"

OnServerValidate="ValidateNumber"></asp:CustomValidator>

</p>

<p>

<asp:Button id="Button1" onclick="Button1_Click"

runat="server" Text="Button"></asp:Button>

</p>

<p>

<asp:Label id="Label1" runat="server"></asp:Label>

</p>

</form>

</body>

</html>