compare validator to validate date in user control
I have created a user control using calender control and text box
control. When user selects value from calender control, it is shown in
text box control. user can directly enter the date in textbox control.
I have five such user controls on the web form. I tried using compare
validator to compare the dates. It doesn't understand the user control's
Is there a way to do it. Also to achieve this is there any better way to
do it ?
Pls. help !!!
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Re: compare validator to validate date in user control
Couldn't you put the validator inside the user control as TextBox and
Calendar? Sounds reasonable to me as TextBox really is inside the user
control as well and then you wouldn't need to multiply the validation
because of multiple user controls. Inside the user control you specify the
control id for the validator as you would on normal page, that is the ID of
the control to be validated.
However, if you want to separate the validation, you would perhaps expose
TextBox's Text property as new top-level property in the user control and
apply ValidationProperty attribute for it. That way validation framework
would recognize the ID (of the user control) you provide for the validation
Example of the second approach:
**ASCX of the user control:
<%@ Control Language="c#" AutoEventWireup="false"
<asp:Calendar ID="Calendar1" Runat="server" /><br>
<asp:TextBox ID="TextBox1" Runat="server" />
**Code-behind of the user control (the relevant part
public class DemoUserControl : System.Web.UI.UserControl
protected System.Web.UI.WebControls.Calendar Calendar1;
protected System.Web.UI.WebControls.TextBox TextBox1;
public string CalendarText
Then usage on the ASPX Page:
<%@ Page language="c#" Codebehind="login.aspx.cs" AutoEventWireup="false"
<%@ Register TagPrefix="uc1" TagName="DemoUserControl"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<form id="Form1" method="post" runat="server">
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server"
ErrorMessage="Calendar Date is required"
<asp:CompareValidator id="CompareValidator1" runat="server"
ErrorMessage="Insert a valid date!" ControlToValidate="DemoUserControl1"
<asp:Button id="Button1" runat="server" Text="Test it"></asp:Button>
Mansoft tietotekniikka Oy
AspInsiders Member, www.aspinsiders.com
ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com
"Shailesh Katti" <email@example.com> wrote in message
> I have created a user control using calender control and text box
> control. When user selects value from calender control, it is shown in
> text box control. user can directly enter the date in textbox control.
> I have five such user controls on the web form. I tried using compare
> validator to compare the dates. It doesn't understand the user control's
> Is there a way to do it. Also to achieve this is there any better way to
> do it ?
> Pls. help !!!
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
|All times are GMT. The time now is 03:40 PM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.