CustomValidator in UserControl not firing

Posted by Lokeshbasana under ASP.NET on 4/4/2009 | Views : 12069 | Status : [Member] | Replies : 2
I created UserControl With Textbox,Ajax Calender control, RequiredField Validator and CustomValidator

Required Validator is working fine in Textbox but Custom validator is not displaying Error Message.
Without using Usercontrol Custom validator is working (i.e. directly this validation controls placed in Default.aspx)
but using UserControl its not working.

I wrote Date Format Validation in Custom Validor

--------Calender.ascx

<td valign="top">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
<td valign="top">
<cc1:CalendarExtender ID="CalendarExtender1" runat="server" PopupButtonID="TextBox1" Format="dd/MM/yyyy"
TargetControlID="TextBox1">
</cc1:CalendarExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1"
Display="Dynamic" ErrorMessage="Please Choose Date"></asp:RequiredFieldValidator>

<asp:CustomValidator ID="Customvalidator1" Runat="server" Enabled="True" Display="Dynamic" Visible="false"
ClientValidationFunction="ValidateTextBox1" ControlToValidate="TextBox1"
EnableClientScript="False" ErrorMessage="Invalid DateTime Format"
OnServerValidate="CustomValidaorMethod"></asp:CustomValidator>

</td>

-----calender.ascx.cs

public void CustomValidaorMethod(object source, ServerValidateEventArgs args)
{
-- date formating validation code
}

Please give me the reply, this reply will be helpful to me further developing programming skills
Thank u
waiting for yours reply as soon as possible




Responses

Posted by: Majith on: 4/6/2009 [Member] Starter

Up
0
Down
Lokesh,

when you are using CalendarExtender from AJAX refer the below code:

1.Add the targetControlid of your Required Filed Validator Id.

<Tc1:ValidatorCalloutExtender ID="Date" runat="server" TargetControlID="ReqDate" Enabled="False">

</Tc1:ValidatorCalloutExtender>
<asp:RequiredFieldValidator ID="ReqDate" runat="server" ControlToValidate="txtDate" ErrorMessage="Choose Valid Date"></asp:RequiredFieldValidator>


Let me know any Issues,



Lokeshbasana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lokeshbasana on: 4/9/2009 [Member] Starter

Up
0
Down

my problem is not RequiredField validator control its working fine
problem with CustomValidator control in UserControl

calender.ascx:

<asp:CustomValidator ID="Customvalidator1" Runat="server" Enabled="True" Display="Dynamic" Visible="false"
ClientValidationFunction="ValidateTextBox1" ControlToValidate="TextBox1"
EnableClientScript="False" ErrorMessage="Invalid DateTime Format"
OnServerValidate="CustomValidaorMethod"></asp:CustomValidator>

In CustomValidator, OnServerValidate="CustomValidatorMethod"
so CustomValidatorMethod is not firing using UserControl

calender.ascx.cs

public void CustomValidaorMethod(object source, ServerValidateEventArgs args)
{
-- date formating validation code is not firing// but it is firing without using Usercontrol
}

Thanku

Lokeshbasana, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response