Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   compare validator to validate date in user control (http://www.velocityreviews.com/forums/t770561-compare-validator-to-validate-date-in-user-control.html)

Shailesh Katti 07-27-2003 04:07 AM

compare validator to validate date in user control
 

Hi,

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
ID.

Is there a way to do it. Also to achieve this is there any better way to
do it ?

Pls. help !!!

Thanks.

Shailesh


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Teemu Keiski 07-28-2003 11:20 AM

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
control.

Example of the second approach:

**ASCX of the user control:

<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="DemoUserControl.ascx.cs"
Inherits="ControlDemoApp.DemoUserControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<asp:Calendar ID="Calendar1" Runat="server" /><br>
<asp:TextBox ID="TextBox1" Runat="server" />

**Code-behind of the user control (the relevant part

[ValidationProperty("CalendarText")]
public class DemoUserControl : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Calendar Calendar1;
protected System.Web.UI.WebControls.TextBox TextBox1;

public string CalendarText
{
get
{
return TextBox1.Text;
}
set
{
TextBox1.Text=value;
}
}
....
}

Then usage on the ASPX Page:
<%@ Page language="c#" Codebehind="login.aspx.cs" AutoEventWireup="false"
Inherits="ControlDemoApp.login" %>
<%@ Register TagPrefix="uc1" TagName="DemoUserControl"
Src="DemoUserControl.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>

</HEAD>
<body >

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

<uc1:DemoUserControl id="DemoUserControl1"
runat="server"></uc1:DemoUserControl>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server"
ErrorMessage="Calendar Date is required"
ControlToValidate="DemoUserControl1"></asp:RequiredFieldValidator>
<asp:CompareValidator id="CompareValidator1" runat="server"
ErrorMessage="Insert a valid date!" ControlToValidate="DemoUserControl1"
Operator="DataTypeCheck" Type="Date"></asp:CompareValidator>
<asp:Button id="Button1" runat="server" Text="Test it"></asp:Button>

</form>

</body>
</HTML>

--
Teemu Keiski
MCP, Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

AspInsiders Member, www.aspinsiders.com
ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com



"Shailesh Katti" <shaileshkatti@yahoo.com> wrote in message
news:ekoqpS$UDHA.2564@tk2msftngp13.phx.gbl...
>
> Hi,
>
> 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
> ID.
>
> Is there a way to do it. Also to achieve this is there any better way to
> do it ?
>
> Pls. help !!!
>
> Thanks.
>
> Shailesh
>
>
> *** 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 01:54 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.